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 7.0k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on 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

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • SPlattenS SPlatten

      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

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on 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
      • SPlattenS SPlatten

        @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);
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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!

        SPlattenS 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @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.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on 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.

          SPlattenS JonBJ KroMignonK 3 Replies Last reply
          2
          • JonBJ JonB

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

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on 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

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

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

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on 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.HilkJ J.Hilk

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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 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??

                SPlattenS 1 Reply Last reply
                0
                • JonBJ JonB

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

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #11

                  @JonB , whats wrong ?

                  Kind Regards,
                  Sy

                  JonBJ 1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    @JonB , whats wrong ?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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....

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

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

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on 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)

                      SPlattenS 1 Reply Last reply
                      0
                      • SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by
                        #14

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

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        0
                        • SPlattenS SPlatten

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

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on 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?

                          SPlattenS 1 Reply Last reply
                          0
                          • KroMignonK KroMignon

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

                            SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on 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

                            JonBJ KroMignonK 2 Replies Last reply
                            0
                            • JonBJ JonB

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

                              SPlattenS Offline
                              SPlattenS Offline
                              SPlatten
                              wrote on 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

                              JonBJ 1 Reply Last reply
                              0
                              • SPlattenS SPlatten

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

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on 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
                                • JonBJ JonB

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

                                  KroMignonK Offline
                                  KroMignonK Offline
                                  KroMignon
                                  wrote on 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
                                  • SPlattenS SPlatten

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

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on 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........

                                    SPlattenS 1 Reply Last reply
                                    0
                                    • JonBJ JonB

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

                                      SPlattenS Offline
                                      SPlattenS Offline
                                      SPlatten
                                      wrote on last edited by
                                      #21

                                      @JonB, just did that adding:

                                      qDebug() << "connect: " << blnRC;
                                      

                                      Shown in console as:

                                      connect: false
                                      

                                      Kind Regards,
                                      Sy

                                      JonBJ 2 Replies Last reply
                                      0
                                      • SPlattenS SPlatten

                                        @JonB, just did that adding:

                                        qDebug() << "connect: " << blnRC;
                                        

                                        Shown in console as:

                                        connect: false
                                        
                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by
                                        #22

                                        @SPlatten
                                        OK, damn!
                                        Just I warn you now: do not rely on what you see in the debugger for values of variables...!

                                        1 Reply Last reply
                                        0
                                        • SPlattenS SPlatten

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

                                          KroMignonK Offline
                                          KroMignonK Offline
                                          KroMignon
                                          wrote on last edited by
                                          #23

                                          @SPlatten said in QObject::connect returns false:

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

                                          Are you sure header files are in HEADERS in your PRO file?
                                          Did you (re)run qmake?
                                          You could also try to remove the build directory to force moc re-run.

                                          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
                                          2

                                          • Login

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