Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signals in iteration statements
Qt 6.11 is out! See what's new in the release blog

Signals in iteration statements

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sorin
    wrote on last edited by
    #1

    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
    }@

    Thanks!

    There are only 10 types of people in the world: Those who understand binary, and those who don't

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • ZlatomirZ Offline
        ZlatomirZ Offline
        Zlatomir
        wrote on last edited by
        #3

        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)

        https://forum.qt.io/category/41/romanian

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          Do your widgets lies in one thread? Correct? Then why you want use signals?
          You can call slot directly:
          @for( some conditions )
          {
          secondWidget->someSlot();
          }@

          --
          Vasiliy

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved