Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Is signal-slot blocking.??
aekam last edited by
suppose i create an object of a class which has a slot. i connect this slot to any system signal like say readyRead() in constructor.
can the execution of signal-slot, block my calling function, where i created instance of the class.??
fluca1978 last edited by
Not sure, are you asking if the constructor could block on processing a signal? I think this could happen if you have a multithreaded application (therefore signals are coming independently from the thread that is building the instance).
"This":http://developer.qt.nokia.com/doc/qt-4.8/threads-qobject.html could help.
lgeyer last edited by
Can you please rephrase your question. It is completely incomprehensible (to me).
There is no way a slot connected in the constructor is execute before the constructor is finished, neither in single-threaded applications (the thread is executing your constructor) nor in multithreaded applications (the signal is dispatched as soon as the execution returns to the event loop, which happens in any case after the constructor has returned).
I see this only happening if you <code>qApp->processEvents()</code> or <code>moveToThread(this)</code> in your constructor - both highly questionable. Rule of thumb: just don't do it.
shoyeb last edited by
no, this will not block the execution of your program.
miroslav last edited by
If the question is whether emitting a signal blocks the caller until the slots have been called, then the correct answer is "it depends".
In a single-threaded case, signal-slot connections are direct connections, meaning the slots get called when the signal is emitted (the signal function is called). The signal method returns after all connected slots have been called. In a multi-threaded case, it depends on whether the sender and receiver are associated with the same thread.
Have a look at http://doc.qt.nokia.com/4.7-snapshot/thread-basics.html for more details.
kinjalp last edited by
please explained your problem in detail.
andre last edited by
miroslav is right, but I guess the more correct answer is: it depends on what connection flag you used when you connected the signal and the slot. The default flag will result in different behaviour in threaded and non-threaded cases.