Signals in iteration statements

  • 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
    emit someSignal();
    // Here I want to wait for my someSlot() to finish his job and after that continue with iteration


  • 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.

  • If you use "Qt::DirectConnection": as connectionType when you call "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)

  • Do your widgets lies in one thread? Correct? Then why you want use signals?
    You can call slot directly:
    @for( some conditions )

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.