[Development] invokeMethod() with function pointers

Olivier Goffart olivier at woboq.com
Mon Jan 16 10:34:30 CET 2017

On Samstag, 14. Januar 2017 17:28:01 CET Benjamin TERRIER wrote:
> Hi everyone,
> I'm trying to contribute by making QMetaObject::invokeMethod() take function
> pointers instead of function names.
> I've come up with something that works by looking at the code of
> QMetaObject::invokeMethod, QObject::connect and QMetaObject::activate.

Thanks for your contribution.

What's the use case for this function? For direct call you better of calling 
the function directly,  and the equivalent of QueuedConnection can be achieved 
with QTimer::singleShot.
Nevertheless, i guess it's worth adding for the sake of consistency.

However, I don't really like QGenericArgument which forces to use Q_ARG. This 
was just a workaround back in the Qt 4 days, around the lack of template 
member function and variadic template. Since we know the arguments of the slot 
at compile time, it would be much nicer to pass the arguments directly. 

> However it does not check for parameters and it is implemented as a function
> of QObject (because I needed QSlotObjects classes which are not available
> in qobjectdef.h). 

But for consistency, it should stay in QMetaObject, I'd say.  We might need to 
move a few more things to qobjectdefs_impl.h to make it happen.

> It can handle QObject member functions and functors in
> which case  "this" is used to select the event loop (like connect()
> functions).
> I've uploaded my change as a draft on gerrit:
> https://codereview.qt-project.org/#/c/182339/
> Here is the link to the relevant bug report:
> https://bugreports.qt.io/browse/QTBUG-37253
> I welcome any comment and feedback.
> BR,
> Benjamin Terrier


Woboq - Qt services and support - https://woboq.com - https://code.woboq.org

More information about the Development mailing list