If i invoke QMetaObject::invokeMethod from thread to singletone is the invokation is still in that thread?
-
wrote on 31 Jan 2012, 13:05 last edited by
Hi
i have thread (working great ) that invoking method in singletone object like this:@bool bInvokeUpdate= QMetaObject::invokeMethod(ApiManager::getInstance(),
"updateMainWindowTree",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, bReturnUpdate));@im using Qt::BlockingQueuedConnection so i can continue the thread work based on bool value .. any way
my question is dose this invocation remains in the thread ? or it cause to method to be preformed in the main thread ?quick update ...
when i debug the app when im in the thread i see in the debugger that im in thread id xxxx
but when i set breakpoint in the updateMainWindowTree method , i see it jumping to the mainthread .
so what does it mean that i keep invoking functions from the main thread ? how can i avoid it? -
wrote on 31 Jan 2012, 16:27 last edited by
The code runs in the thread the singleton belongs to, which is either the thread it was created (most probably the main thread) or moved to (using QObject::moveToThread()).
As judging from your method name <code>updateMainWindowTree</code> one should mention that you cannot do any GUI related operations outside the main thread. This includes updating any widgets.
-
wrote on 31 Jan 2012, 20:59 last edited by
what about if i "emit" SIGNAL from Thread to GUI main thread ?
what is better to use "emit" or QMetaObject::invokeMethod
to update GUI , yes i know is abit different question . -
wrote on 1 Feb 2012, 08:22 last edited by
You can of course trigger the update from another thread, provided that the update itself runs in the main thread.
There is no difference between emit and QMetaObject::invokeMethod(), besides that emit invokes all connected methods whereas QMetaObject::invokeMethod() invokes just a single method.
-
wrote on 18 Feb 2012, 11:43 last edited by
Thanks for the insight! Im current trying to figure out why my app goes boom (newbie programmer) and I did not realize that about QMetaObject::InvokeMethod.