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. Signal order
Forum Updated to NodeBB v4.3 + New Features

Signal order

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 3.3k 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.
  • TelergoelT Offline
    TelergoelT Offline
    Telergoel
    wrote on last edited by
    #1

    Hi,
    There are two slots in my program:

    • void Dialog::on_energy_in_editingFinished()
    • void Dialog::on_button_clicked()

    Knowing that "button" is default, when "Enter" key is pressed while the focus is on the "energy" spinbox, both "editingFinished()" and "clicked()" signals are emitted.

    However, I need the first slot to always be executed before the second one, when "Enter" key is pressed. How can I make sure that the signals are emitted in the correct order?

    Thank you,
    Telergoel

    kshegunovK 1 Reply Last reply
    0
    • TelergoelT Telergoel

      Hi,
      There are two slots in my program:

      • void Dialog::on_energy_in_editingFinished()
      • void Dialog::on_button_clicked()

      Knowing that "button" is default, when "Enter" key is pressed while the focus is on the "energy" spinbox, both "editingFinished()" and "clicked()" signals are emitted.

      However, I need the first slot to always be executed before the second one, when "Enter" key is pressed. How can I make sure that the signals are emitted in the correct order?

      Thank you,
      Telergoel

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Telergoel
      Hello,

      However, I need the first slot to always be executed before the second one, when "Enter" key is pressed. How can I make sure that the signals are emitted in the correct order?

      Why? You should not depend on the order (it's implementation defined), the same as with events - do not require a specific order.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • TelergoelT Offline
        TelergoelT Offline
        Telergoel
        wrote on last edited by Telergoel
        #3

        Thanks for your answer!

        My point is that the second slot execution needs a value that is calculated in the first slot... That's why I need the signals to respect a specific order.

        If it's implementation-defined, I don't know what to type to make sure signals are sent in the order I need. When I press "Enter", which signal is emitted in the first place? "editingFinished()" or "clicked()"?

        What do you advise me to do?

        kshegunovK 1 Reply Last reply
        0
        • TelergoelT Telergoel

          Thanks for your answer!

          My point is that the second slot execution needs a value that is calculated in the first slot... That's why I need the signals to respect a specific order.

          If it's implementation-defined, I don't know what to type to make sure signals are sent in the order I need. When I press "Enter", which signal is emitted in the first place? "editingFinished()" or "clicked()"?

          What do you advise me to do?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @Telergoel

          My point is that the second slot execution needs a value that is calculated in the first slot... That's why I need the signals to respect a specific order. ... What do you advise me to do?

          Then you need to signal from your own object. Think event driven - you wouldn't post a mouse event before the mouse has moved, right? So it's the same here. Qt's signal will trigger your slot, you do whatever calculations you need and raise your own signal - thus notifying any object that's interested in it. That signal can be connected to another slot and so on. E.g:

          class MyObject : public QObject
          {
              Q_OBJECT
          
          signals:
              void myDataReady(int);
          
          private slots:
              void prepareMyData();
          };
          
          void MyObject::prepareMyData()
          {
              // Do whatever calculation you need to do (this is connected to the clicked signal).
              int calculatedValue = 0;
          
              // When everything is ready, emit the appropriate signal
              emit myDataReady(calculatedValue);
          }
          

          So you connect things up:

          QPushButton button; //< Comes from the dialog 
          MyObject handler; //< This is the object handling the signal (QObject in this simple example, but can be anything).
          
          QObject::connect(&button, SIGNAL(clicked()), &handler, SLOT(prepareMyData()));
          QObject::connect(&handler, SIGNAL(myDataReady(int)), ...); //< Connect as needed
          

          If it's implementation-defined

          Slots are called in the order of the connection done to the signal when working in single thread and there's no guaranteed order when working in multiple thread environment. But this is an implementation detail and can change at any one time. As for the signals, I don't know which is emitted first I haven't checked the source.

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          3
          • TelergoelT Offline
            TelergoelT Offline
            Telergoel
            wrote on last edited by
            #5

            Okay, I've got it now :)
            Thanks a lot for your help, I appreciate.
            Regards

            kshegunovK 1 Reply Last reply
            0
            • TelergoelT Telergoel

              Okay, I've got it now :)
              Thanks a lot for your help, I appreciate.
              Regards

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @Telergoel
              I'm glad I could help.
              Kind regards.

              Read and abide by the Qt Code of Conduct

              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