[Development] invokeMethod() with function pointers

Benjamin TERRIER b.terrier at gmail.com
Mon Jan 16 19:23:07 CET 2017

2017-01-16 10:34 GMT+01:00 Olivier Goffart <olivier at woboq.com>:

> 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.

Talking for me here, I use QMetaObject::invokeMethod() to call slots of
QObject accross threads.
I could make use of the new form to call any function (not only slots) and
to have some checks during compilation.

The QTimer solution could work, but you cannot add parameters without using

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.

Agreed. I've got something working with variadic templates, I'll update the
change later.

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.

Can this be done in the same commit? Or do I need to make 2 changes?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170116/b4c63652/attachment.html>

More information about the Development mailing list