Re: QMetaObject::invokeMethod
Hi Robert, Still abroad, therefore very briefly: 1) At the risk of being pedantic: This has nothing to do with C++, but with Qt/MOC. This wouldn't even work with plain C++. There's a slightly more modern pointer-to-member-function version, but that didn't compile on qt5.5. 2) I use this to call a function across thread boundaries (notably to transport data from a worker thread to the UI thread). For unknown reasons, QNetworkManager and QMediaPlayer refused to work in a non-UI thread. 3) You are right: This could be done just as well by sending a signal from the worker thread-object to a slot in the UI thread-object. In a PR I think Lubomir (sorry, if I mis-attribute) noted that connecting a signal from an object to itself is weird and therefore in this case invokeMethod was preferred. This just stuck, even if in this case it's connecting different objects. 4) I don't have any problems with this being changed to signal/slot, I would just ask to wait until the "Video-lite" PR is in master, so that we don't step on each other's toes. Berthold ___ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
Re: QMetaObject::invokeMethod
On 7 July 2018 at 22:36, Robert Helling wrote: > Thiago, > > On 7. Jul 2018, at 18:54, Thiago Macieira wrote: > > 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(). > > > but this doesn’t seem the application in the subsurface code. If you do > > git grep invokeMethod > > you will find the instances. > the image related calls that don't have a connection type and are technically using Qt::AutoConnection, which detects separate threads. invokeMethod() can be also used to call functions in QML objects. lubomir -- ___ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
Re: QMetaObject::invokeMethod
Thiago, > On 7. Jul 2018, at 18:54, Thiago Macieira wrote: > > 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(). but this doesn’t seem the application in the subsurface code. If you do git grep invokeMethod you will find the instances. Best Robert signature.asc Description: Message signed with OpenPGP ___ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
Re: QMetaObject::invokeMethod
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 ___ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface