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/slot not working
Qt 6.11 is out! See what's new in the release blog

signal/slot not working

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 9 Posters 5.0k Views 5 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #17

    Hi,

    @mzimmers said in signal/slot not working:

    mt = m_msg.getType();
    switch (mt)

    When is m_msg updated ? You could be processing the same value twice.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #18
      void Worker::processSerial(QByteArray buff)
      {
          MsgType mt;
          string s;
      
          s.assign(buff);
      
          m_msg.decodeXml(s);
          mt = m_msg.getType();
          switch (mt)
          {
          case MSG_DISCOVERY_ACK:
              emit newSerialData(&m_msg);
              break;
          case MSG_WIFI_SETUP_ACK:
              emit wifiSetupAckReceived(&m_msg);
              break;
      ...
      

      Besides, the signal is being emitted (at least according to the debugger).

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #19

        Insert a qDebug() before the emit to be 100% sure.

        One more idea... this method isn't called once, is it? Because if it is called once, and your have a break; in your switch then only the first ack will trigger MSG_DISCOVERY_ACK, then it will break and never bother to check if MSG_WIFI_SETUP_ACK is satisfied or not.

        (Z(:^

        1 Reply Last reply
        0
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #20

          Let's be 100% clear for everyone: because of your separate threads, these are queued-connection signals, right? So the slots won't be called during the emits, only later on, and we're all clear about this, right?

          @sierdzio said in signal/slot not working:

          Insert a qDebug() before the emit to be 100% sure.

          Damn right, I'd have expected you to do this to make sure already!

          sierdzioS 1 Reply Last reply
          0
          • JonBJ JonB

            Let's be 100% clear for everyone: because of your separate threads, these are queued-connection signals, right? So the slots won't be called during the emits, only later on, and we're all clear about this, right?

            @sierdzio said in signal/slot not working:

            Insert a qDebug() before the emit to be 100% sure.

            Damn right, I'd have expected you to do this to make sure already!

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #21

            @JonB said in signal/slot not working:

            Let's be 100% clear for everyone: because of your separate threads, these are queued-connection signals, right? So the slots won't be called during the emits, only later on, and we're all clear about this, right?

            Yes, they will be queued. Good point, that adds one, although rare, possibility: the event loop may be too busy to process the queue.

            (Z(:^

            1 Reply Last reply
            0
            • mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #22

              Sigh.

              I really should never have become a programmer.

              This was pure cockpit error on my part. Everyone feel free to negrate me.

              And Jon, email me your postal address; I'll send you a bottle of the good stuff.

              Sorry, everyone.

              J.HilkJ 1 Reply Last reply
              0
              • mzimmersM mzimmers

                Sigh.

                I really should never have become a programmer.

                This was pure cockpit error on my part. Everyone feel free to negrate me.

                And Jon, email me your postal address; I'll send you a bottle of the good stuff.

                Sorry, everyone.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #23

                @mzimmers So, what was it, not be shy, we won't judge :D

                I was about to suggest changing the argument of your signals to actual objects (not pointers or references) to force the compiler the acknowledge that copying has to be done, and that the lifetime of the objects do not interfere.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                mzimmersM 1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #24

                  Do not despair :-) I'm pretty sure all of us here had spent a whole day (or 3...) looking for some nasty bug only to discover a missing semicolon :D

                  (Z(:^

                  J.HilkJ 1 Reply Last reply
                  1
                  • sierdzioS sierdzio

                    Do not despair :-) I'm pretty sure all of us here had spent a whole day (or 3...) looking for some nasty bug only to discover a missing semicolon :D

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by J.Hilk
                    #25

                    @sierdzio said in signal/slot not working:

                    Do not despair :-) I'm pretty sure all of us here had spent a whole day (or 3...) looking for some nasty bug only to discover a missing semicolon :D

                    very true, my personal favorite:

                    if(conditionA == true);
                         callFunctionA();
                    

                    and callFunctionA() always being executed. Now days QtC warns you about it, but that wasn't always the case. Long days of debugging ....


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @mzimmers So, what was it, not be shy, we won't judge :D

                      I was about to suggest changing the argument of your signals to actual objects (not pointers or references) to force the compiler the acknowledge that copying has to be done, and that the lifetime of the objects do not interfere.

                      mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #26

                      @J-Hilk said in signal/slot not working:

                      @mzimmers So, what was it, not be shy, we won't judge :D

                      Ridiculously stupid. My Wifisetup object had:

                      this->done(0);
                      

                      at the end of a slot for a button push. Once upon a time, this was correct, but the protocol changed, so now we wait for a confirmation before exiting. (The code that I posted was part of this.) That's where the new done() is. Unfortunately, some doofus who shall remain nameless, forgot to remove the original one. So, the signal fired, but the object containing the slot had already been destroyed.

                      I guess I'm a little surprised that I don't get some kind of error/warning, but I guess Qt's OK with signals just disappearing into the bit bucket.

                      I was about to suggest changing the argument of your signals to actual objects (not pointers or references) to force the compiler the acknowledge that copying has to be done, and that the lifetime of the objects do not interfere.

                      This is probably a good idea for future reference. As an embedded software engineer, I often find resources to be somewhat limited, so I'm accustomed to rather parsimonious programming. I used pointers to save stack space, which is probably silly on a desktop.

                      S JonBJ 2 Replies Last reply
                      2
                      • fcarneyF Offline
                        fcarneyF Offline
                        fcarney
                        wrote on last edited by
                        #27

                        Do this:

                        //this->done(0);  // memory management test 001
                        

                        Now its a feature!

                        C++ is a perfectly valid school of magic.

                        1 Reply Last reply
                        1
                        • mzimmersM mzimmers

                          @J-Hilk said in signal/slot not working:

                          @mzimmers So, what was it, not be shy, we won't judge :D

                          Ridiculously stupid. My Wifisetup object had:

                          this->done(0);
                          

                          at the end of a slot for a button push. Once upon a time, this was correct, but the protocol changed, so now we wait for a confirmation before exiting. (The code that I posted was part of this.) That's where the new done() is. Unfortunately, some doofus who shall remain nameless, forgot to remove the original one. So, the signal fired, but the object containing the slot had already been destroyed.

                          I guess I'm a little surprised that I don't get some kind of error/warning, but I guess Qt's OK with signals just disappearing into the bit bucket.

                          I was about to suggest changing the argument of your signals to actual objects (not pointers or references) to force the compiler the acknowledge that copying has to be done, and that the lifetime of the objects do not interfere.

                          This is probably a good idea for future reference. As an embedded software engineer, I often find resources to be somewhat limited, so I'm accustomed to rather parsimonious programming. I used pointers to save stack space, which is probably silly on a desktop.

                          S Offline
                          S Offline
                          shaan7
                          wrote on last edited by
                          #28

                          @mzimmers said in signal/slot not working:

                          I guess I'm a little surprised that I don't get some kind of error/warning, but I guess Qt's OK with signals just disappearing into the bit bucket.

                          Yeah, except in cases where it bites (like this), it is quite convenient that you can delete QObjects and signal/slot connections are automatically removed.

                          1 Reply Last reply
                          0
                          • mzimmersM mzimmers

                            @J-Hilk said in signal/slot not working:

                            @mzimmers So, what was it, not be shy, we won't judge :D

                            Ridiculously stupid. My Wifisetup object had:

                            this->done(0);
                            

                            at the end of a slot for a button push. Once upon a time, this was correct, but the protocol changed, so now we wait for a confirmation before exiting. (The code that I posted was part of this.) That's where the new done() is. Unfortunately, some doofus who shall remain nameless, forgot to remove the original one. So, the signal fired, but the object containing the slot had already been destroyed.

                            I guess I'm a little surprised that I don't get some kind of error/warning, but I guess Qt's OK with signals just disappearing into the bit bucket.

                            I was about to suggest changing the argument of your signals to actual objects (not pointers or references) to force the compiler the acknowledge that copying has to be done, and that the lifetime of the objects do not interfere.

                            This is probably a good idea for future reference. As an embedded software engineer, I often find resources to be somewhat limited, so I'm accustomed to rather parsimonious programming. I used pointers to save stack space, which is probably silly on a desktop.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #29

                            @mzimmers said in signal/slot not working:

                            I guess I'm a little surprised that I don't get some kind of error/warning, but I guess Qt's OK with signals just disappearing into the bit bucket.

                            Not sure what you're surprised about? What do you want a warning for? (And I'm glad there isn't one.) As @shaan7 says, in Qt deleting the object used as the source of a signal or the destination of a slot in a connect() means that connection is automatically removed with it, and thank goodness for that!

                            If you ask me to give you a phone call when I wake up in the morning, and I have a heart attack and die during the night, or you die, either way no phone call gets made and we are all happy about it, without anyone sending a warning in the post :)

                            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