What I have is these two calls to a method in another object in another thread.
QMetaObject::invokeMethod(object, "method", Qt::variousOptionalParameters,
Q_ARG(int, a), Q_ARG(int, b), Q_ARG(float, c), Q_ARG(QString, d));
and
object->method(a, b, c, d);
They do exactly the same thing (in this case, at least, where they update some GUI elements, and also the region of interest for OpenCV thread). What's the difference between the two?
QObject and derived can have thread affinity, and if they do, you can schedule queued calls to its methods. This can be useful as an easy synchronization where performance is not critical, obviously, you won't be using queued connections in a tight loop, because you will get massive performance penalty.
Just like deleteLater(), queued calls are useful when you want the call to occur "in the clean", in between event loop iterations, to minimize the possible side effects of other ongoing operations, when you don't want anything else running that may have a side effect on the queued operation, or you want everything that was intended to affect the operation to have been executed. Also, in the case of deletion, this will remove any pending events, connections and whatnot.
The direct call will be that much faster, but you don't have the safety. In most cases you could be fine, which will make an eventual problem that much harder to pinpoint.
If you plan on doing that between different threads, you must implement your own synchronization, for example a QMutex and make sure all access to that object passes through it. It will be a lot faster than using queued connections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With