[Development] invokeMethod() with function pointers
annulen at yandex.ru
Mon Jan 16 10:57:01 CET 2017
16.01.2017, 12:34, "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.
QTimer::singleShot creates temporary QSingleShotTimer object, which does not seem to be efficient solution if same method needs to be called a lot of times in QueuedConnection way.
Also, from quick glance it seems like there is no fast path for zero timer interval in startTimer(), so internal timer is registered in event loop for each call.
> 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()
>> I've uploaded my change as a draft on gerrit:
>> Here is the link to the relevant bug report:
>> I welcome any comment and feedback.
>> Benjamin Terrier
> Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
> Development mailing list
> Development at qt-project.org
More information about the Development