Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Signals in iteration statements
Sorin last edited by
these days I run into a new thing for me as a beginner Qt developer and I didn't find a solution for it: How to wait on signal/slot to finish job and after that continue with iteration?
Lets say I have two widgets connected:
@QObject::connect( firstWidget, SIGNAL( someSignal () ), secondWidget, SLOT( someSlot() );
for( some conditions )
//do some stuff
// Here I want to wait for my someSlot() to finish his job and after that continue with iteration
andre last edited by
If you can avoid this kind of thing, then do so. If you are dependent on the signals' handling being finished before you continue, you probably need a direct method invokation, not a signal emission. Having said that: direct signal connections are already guaranteed to be finished. However, you can not guarantee that nobody will connect to your signal from another thread or using a queued connection in the same thread.
Zlatomir last edited by
If you use "Qt::DirectConnection":http://doc.qt.nokia.com/latest/qt.html#ConnectionType-enum as connectionType when you call "connect":http://doc.qt.nokia.com/latest/qobject.html#connect the slot/slots should be executed immediately (this only works if both QObject involved are in the same thread, and as far as i know is the default behavior in this case)
vsorokin last edited by
Do your widgets lies in one thread? Correct? Then why you want use signals?
You can call slot directly:
@for( some conditions )