[Qt-interest] Forcing a signal "emit" to be queued

Mohammed Sameer msameer at foolab.org
Mon Mar 21 19:34:28 CET 2011


On Mon, Mar 21, 2011 at 05:53:58PM +0200, Mohammed Sameer wrote:
> On Mon, Mar 21, 2011 at 05:24:36PM +0530, Mandeep Sandhu wrote:
> > > No, actually that will allow you to do this without using a private signal
> > > at all. You can invoke a signal using invokeMethod() with a queued
> > > connection, or you can use the single shot timer connected to your public
> > > signal. Both methods would rid you of the private signal, and hence of the
> > > private class (if you did not need this for other purposes anyway).
> > 
> > Oh yes, I forgot that I could give a signal name to invokeMethod()
> > too. Though the only 'technical' limitation here is the number of args
> > that one can pass to invokeMethod (max is 10). Though it might not be
> > much of an issue in most cases.
> 
> I would really put all the arguments in a class if I need to pass 10 arguments.
> It makes it easier to users of the class and also makes it hard to mistype
> an argument.
> 
> 
> > As for the singleShot approach, will it have an overhead of creating a
> > OS  specific timer underneath (even for a timeout of 0)? Not sure how
> > heavy creation/destruction of such timer is.
> 
> I think it used to do that but got fixed at some point. Not really sure.
> But then, why do you care much ?

Just checked the code and QTimer::singleShot() uses QMetaObject::invokeMethod()
with a Qt::QueuedConnection if msec is 0

-- 
GPG-Key: 0xA3FD0DF7 - 9F73 032E EAC9 F7AD 951F  280E CB66 8E29 A3FD 0DF7
Debian User and Developer.
Homepage: www.foolab.org



More information about the Qt-interest-old mailing list