Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject::connect returns false
Qt 6.12 LTS is out! See what's new in the release blog

QObject::connect returns false

Scheduled Pinned Locked Moved Solved General and Desktop
48 Posts 5 Posters 15.9k 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 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 Online
      J.HilkJ Online
      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
                                      • 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
                                        #24

                                        @SPlatten
                                        Like I said, have you done a delete and fresh rebuild?
                                        Does clsTimeEmu have Q_OBJECT in it?

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

                                          @J-Hilk , @JonB , @KroMignon , I've looked at both moc files, moc_clsTimeEmu.cpp has the signal:

                                          // SIGNAL_0
                                          void clsTimeEmu::epoch(int _t1)
                                          {
                                              void *_a[] = { 0, const_cast<void*>reinterpret_cast<const void*>(&_t)) };
                                              QMetaObject::activate(this, &staticMetaObject, 0, _a);
                                          }
                                          

                                          moc_clsSchdSrv.cpp does not have anything that looks like the slot, no mention of updateTime at all, why ?

                                          Kind Regards,
                                          Sy

                                          J.HilkJ KroMignonK JonBJ 3 Replies Last reply
                                          0

                                          • Login

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