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. QObject::connect returns false
Forum Updated to NodeBB v4.3 + New Features

QObject::connect returns false

Scheduled Pinned Locked Moved Solved General and Desktop
48 Posts 5 Posters 6.4k 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
    SPlatten
    wrote on 26 Apr 2022, 11:36 last edited by SPlatten
    #1

    Under what scenario will a connect return false?

    I have two objects both are valid, I create the signalling object:

    clsTimeEmu* pobjEmulator(new clsTimeEmu);
    

    I create the receiving object that has the slot:

    clsTimeSync* pobjService(new clsTimeSync);
    

    Then the connection:

    bool blnRc(QObject::connect(pobjEmulator, SIGNAL(epoch(long)), pobjService, SLOT(updateTime(long))));
    

    blnRc contains false. What could explain this?

    Qt version in this case is 4.8.4

    Kind Regards,
    Sy

    J J K 3 Replies Last reply 26 Apr 2022, 11:41
    0
    • S SPlatten
      26 Apr 2022, 12:10

      @JonB , please see the edited post which includes the derived class, sorry.

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 26 Apr 2022, 12:11 last edited by J.Hilk
      #36

      @SPlatten your derived class will need the Q_OBJECT macro as well, if it defines slots/signals


      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.

      S 1 Reply Last reply 26 Apr 2022, 12:13
      1
      • S SPlatten
        26 Apr 2022, 11:36

        Under what scenario will a connect return false?

        I have two objects both are valid, I create the signalling object:

        clsTimeEmu* pobjEmulator(new clsTimeEmu);
        

        I create the receiving object that has the slot:

        clsTimeSync* pobjService(new clsTimeSync);
        

        Then the connection:

        bool blnRc(QObject::connect(pobjEmulator, SIGNAL(epoch(long)), pobjService, SLOT(updateTime(long))));
        

        blnRc contains false. What could explain this?

        Qt version in this case is 4.8.4

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 26 Apr 2022, 11:41 last edited by J.Hilk
        #2

        @SPlatten said in QObject::connect returns false:

        blnRc contains false. What could explain this?

        The connection is invalid if QObject::connect was not able to find the signal or the slot, or if the arguments do not match.

        have you checked signal and slot declaration?
        also, is the Q_OBJECT macro in both header files?


        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
        2
        • S SPlatten
          26 Apr 2022, 11:36

          Under what scenario will a connect return false?

          I have two objects both are valid, I create the signalling object:

          clsTimeEmu* pobjEmulator(new clsTimeEmu);
          

          I create the receiving object that has the slot:

          clsTimeSync* pobjService(new clsTimeSync);
          

          Then the connection:

          bool blnRc(QObject::connect(pobjEmulator, SIGNAL(epoch(long)), pobjService, SLOT(updateTime(long))));
          

          blnRc contains false. What could explain this?

          Qt version in this case is 4.8.4

          J Offline
          J Offline
          JonB
          wrote on 26 Apr 2022, 11:41 last edited by
          #3

          @SPlatten
          Apart from Q_ASSERT(pobjEmulator); Q_ASSERT(pobjService);, how do we know what the signatures of your signal & slot methods actually look like?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SPlatten
            wrote on 26 Apr 2022, 11:44 last edited by
            #4

            @J-Hilk , @JonB , the signal prototype in the class clsTimeEmu:

            signals:
                void epoch(long lngTime);
            

            The slot prototype in the class clsTimeSync:

            public slots:
                void updateTime(long lngTimeNow);
            

            Kind Regards,
            Sy

            J J 2 Replies Last reply 26 Apr 2022, 11:46
            0
            • S SPlatten
              26 Apr 2022, 11:36

              Under what scenario will a connect return false?

              I have two objects both are valid, I create the signalling object:

              clsTimeEmu* pobjEmulator(new clsTimeEmu);
              

              I create the receiving object that has the slot:

              clsTimeSync* pobjService(new clsTimeSync);
              

              Then the connection:

              bool blnRc(QObject::connect(pobjEmulator, SIGNAL(epoch(long)), pobjService, SLOT(updateTime(long))));
              

              blnRc contains false. What could explain this?

              Qt version in this case is 4.8.4

              K Offline
              K Offline
              KroMignon
              wrote on 26 Apr 2022, 11:46 last edited by
              #5

              @SPlatten said in QObject::connect returns false:

              What could explain this?

              There are several possibilities:

              • signals do not exist (or bad signature)
              • slots do not exist (or bad signature)
              • Q_OBJECT is missed
              • moc needs to be (re)run
              • typo is signal/slot names

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              1
              • S SPlatten
                26 Apr 2022, 11:44

                @J-Hilk , @JonB , the signal prototype in the class clsTimeEmu:

                signals:
                    void epoch(long lngTime);
                

                The slot prototype in the class clsTimeSync:

                public slots:
                    void updateTime(long lngTimeNow);
                
                J Offline
                J Offline
                JonB
                wrote on 26 Apr 2022, 11:46 last edited by JonB
                #6

                @SPlatten
                Nothing obviously wrong there then. Please put in the Q_ASSERTs to make me happy?!

                And follow all of the suggestions from @KroMignon above!

                S 1 Reply Last reply 26 Apr 2022, 11:49
                0
                • S SPlatten
                  26 Apr 2022, 11:44

                  @J-Hilk , @JonB , the signal prototype in the class clsTimeEmu:

                  signals:
                      void epoch(long lngTime);
                  

                  The slot prototype in the class clsTimeSync:

                  public slots:
                      void updateTime(long lngTimeNow);
                  
                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 26 Apr 2022, 11:48 last edited by
                  #7

                  @SPlatten is this potentially cross thread ?

                  or more in general, the long typdef may not be correctly registered with the meta system.

                  you could use qint32, that should work.


                  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.

                  S J K 3 Replies Last reply 26 Apr 2022, 11:50
                  2
                  • J JonB
                    26 Apr 2022, 11:46

                    @SPlatten
                    Nothing obviously wrong there then. Please put in the Q_ASSERTs to make me happy?!

                    And follow all of the suggestions from @KroMignon above!

                    S Offline
                    S Offline
                    SPlatten
                    wrote on 26 Apr 2022, 11:49 last edited by
                    #8

                    @JonB , so the source now reads:

                    Q_ASSERT(pobjEmulator);
                    Q_ASSERT(pobjService);
                    bool blnRC(QObject::connect(pobjEmulator, SIGNAL(epoch(long))
                                               ,pobjService, SLOT(updateTime(long))));
                    

                    Built and run, no assertions, blnRC is false.

                    Kind Regards,
                    Sy

                    J 1 Reply Last reply 26 Apr 2022, 11:53
                    0
                    • J J.Hilk
                      26 Apr 2022, 11:48

                      @SPlatten is this potentially cross thread ?

                      or more in general, the long typdef may not be correctly registered with the meta system.

                      you could use qint32, that should work.

                      S Offline
                      S Offline
                      SPlatten
                      wrote on 26 Apr 2022, 11:50 last edited by
                      #9

                      @J-Hilk , no, not at the moment, this is just simple test code, nothing complex at all....just literally creating instances of each, call to connect and that is it.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0
                      • J J.Hilk
                        26 Apr 2022, 11:48

                        @SPlatten is this potentially cross thread ?

                        or more in general, the long typdef may not be correctly registered with the meta system.

                        you could use qint32, that should work.

                        J Offline
                        J Offline
                        JonB
                        wrote on 26 Apr 2022, 11:50 last edited by
                        #10

                        @J-Hilk said in QObject::connect returns false:

                        or more in general, the long typdef may not be correctly registered with the meta system.

                        long, really??

                        S 1 Reply Last reply 26 Apr 2022, 11:50
                        0
                        • J JonB
                          26 Apr 2022, 11:50

                          @J-Hilk said in QObject::connect returns false:

                          or more in general, the long typdef may not be correctly registered with the meta system.

                          long, really??

                          S Offline
                          S Offline
                          SPlatten
                          wrote on 26 Apr 2022, 11:50 last edited by
                          #11

                          @JonB , whats wrong ?

                          Kind Regards,
                          Sy

                          J 1 Reply Last reply 26 Apr 2022, 11:52
                          0
                          • S SPlatten
                            26 Apr 2022, 11:50

                            @JonB , whats wrong ?

                            J Offline
                            J Offline
                            JonB
                            wrote on 26 Apr 2022, 11:52 last edited by
                            #12

                            @SPlatten
                            Sorry, what's wrong with what?
                            My previous post was just expressing surprise to @J-Hilk that long type might not be "registered with the meta system", but he knows more than I....

                            K 1 Reply Last reply 26 Apr 2022, 11:55
                            0
                            • J J.Hilk
                              26 Apr 2022, 11:48

                              @SPlatten is this potentially cross thread ?

                              or more in general, the long typdef may not be correctly registered with the meta system.

                              you could use qint32, that should work.

                              K Offline
                              K Offline
                              KroMignon
                              wrote on 26 Apr 2022, 11:52 last edited by
                              #13

                              @J-Hilk said in QObject::connect returns false:

                              or more in general, the long typdef may not be correctly registered with the meta system.

                              But this would not affect to connect() call, only slot may not be called if sender and receiver not in same thread.

                              For my comprehension of QObject signals/slots, connect() will only fail if no machting signal or slot signature are found in meta-data. Which are generated by moc.

                              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                              S 1 Reply Last reply 26 Apr 2022, 11:53
                              0
                              • S Offline
                                S Offline
                                SPlatten
                                wrote on 26 Apr 2022, 11:53 last edited by
                                #14

                                I changed long to int just to be sure, same result.

                                Kind Regards,
                                Sy

                                1 Reply Last reply
                                0
                                • S SPlatten
                                  26 Apr 2022, 11:49

                                  @JonB , so the source now reads:

                                  Q_ASSERT(pobjEmulator);
                                  Q_ASSERT(pobjService);
                                  bool blnRC(QObject::connect(pobjEmulator, SIGNAL(epoch(long))
                                                             ,pobjService, SLOT(updateTime(long))));
                                  

                                  Built and run, no assertions, blnRC is false.

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 26 Apr 2022, 11:53 last edited by
                                  #15

                                  @SPlatten said in QObject::connect returns false:

                                  Built and run, no assertions, blnRC is false.

                                  Just checking: how do you know that? I wouldn't trist that if you are only viewing in debugger, as I believe you sometimes do; are you actually outputting the variable's value?

                                  S 1 Reply Last reply 26 Apr 2022, 11:54
                                  0
                                  • K KroMignon
                                    26 Apr 2022, 11:52

                                    @J-Hilk said in QObject::connect returns false:

                                    or more in general, the long typdef may not be correctly registered with the meta system.

                                    But this would not affect to connect() call, only slot may not be called if sender and receiver not in same thread.

                                    For my comprehension of QObject signals/slots, connect() will only fail if no machting signal or slot signature are found in meta-data. Which are generated by moc.

                                    S Offline
                                    S Offline
                                    SPlatten
                                    wrote on 26 Apr 2022, 11:53 last edited by
                                    #16

                                    @KroMignon I will look at the generated moc files, but as you can see from my posts the prototypes are identical.

                                    Kind Regards,
                                    Sy

                                    J K 2 Replies Last reply 26 Apr 2022, 11:54
                                    0
                                    • J JonB
                                      26 Apr 2022, 11:53

                                      @SPlatten said in QObject::connect returns false:

                                      Built and run, no assertions, blnRC is false.

                                      Just checking: how do you know that? I wouldn't trist that if you are only viewing in debugger, as I believe you sometimes do; are you actually outputting the variable's value?

                                      S Offline
                                      S Offline
                                      SPlatten
                                      wrote on 26 Apr 2022, 11:54 last edited by
                                      #17

                                      @JonB , I have a break point in the debugger after the connect and can see it contains false.

                                      Kind Regards,
                                      Sy

                                      J 1 Reply Last reply 26 Apr 2022, 11:55
                                      0
                                      • S SPlatten
                                        26 Apr 2022, 11:53

                                        @KroMignon I will look at the generated moc files, but as you can see from my posts the prototypes are identical.

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 26 Apr 2022, 11:54 last edited by
                                        #18

                                        @SPlatten
                                        Per @KroMignon, just start by emptying out your build output directory and doing a complete rebuild, just in case. Always start there when Qt gives you something "inexplicable" :)

                                        1 Reply Last reply
                                        0
                                        • J JonB
                                          26 Apr 2022, 11:52

                                          @SPlatten
                                          Sorry, what's wrong with what?
                                          My previous post was just expressing surprise to @J-Hilk that long type might not be "registered with the meta system", but he knows more than I....

                                          K Offline
                                          K Offline
                                          KroMignon
                                          wrote on 26 Apr 2022, 11:55 last edited by
                                          #19

                                          @JonB said in QObject::connect returns false:

                                          My previous post was just expressing surprise to @J-Hilk that long type might not be "registered with the meta system", but he knows more than I..

                                          For inter-thread communication, or in case of Qt::QueuedConnection, parameters needs to be copied. So QMeta needs to know how to create a copy of them. This is way all types needs to be registered. Some are already registered my Qt, some not ;)

                                          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                          1 Reply Last reply
                                          0
                                          • S SPlatten
                                            26 Apr 2022, 11:54

                                            @JonB , I have a break point in the debugger after the connect and can see it contains false.

                                            J Offline
                                            J Offline
                                            JonB
                                            wrote on 26 Apr 2022, 11:55 last edited by
                                            #20

                                            @SPlatten said in QObject::connect returns false:

                                            @JonB , I have a break point in the debugger after the connect and can see it contains false.

                                            Noooo.
                                            Like I said, print it out........

                                            S 1 Reply Last reply 26 Apr 2022, 11:56
                                            0

                                            1/48

                                            26 Apr 2022, 11:36

                                            • Login

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