QMetaObject::invokeMethod

Thiago Macieira thiago at macieira.org
Sat Jul 7 09:54:58 PDT 2018


On Saturday, 7 July 2018 08:37:40 PDT Robert Helling wrote:
> Hi,
> 
> I am trying to understand some code that contains invocations of
> 
> QMetaObject::invokeMethod
> 
> I admit I not a C++ person in any sense so could somebody please explain why
> one would use such a thing? Berthold, I guess you introduced these. In
> particular since the Qt documentation says about QMetaObject

Usually, that function is used with Qt::QueuedConnection, which instead of 
calling the method indicated right now, it posts an event to the event queue 
with the arguments you supply. When the event loop gets to that event, the 
method you listed gets finally called.

Another way of doing the same is by using QTimer::singleShot() with a lambda 
that carries your parameters. But this wasn't available before Qt 5.4, so 
there's a lot of code (and muscle memory) using invokeMethod().

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center





More information about the subsurface mailing list