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 not emitted or not received
Forum Updated to NodeBB v4.3 + New Features

Signal not emitted or not received

Scheduled Pinned Locked Moved Solved General and Desktop
34 Posts 4 Posters 12.9k Views 3 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.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #11

    Hi @JKSH,

    I removed the '&' and got the same result - "no such signal".

    JKSHJ 1 Reply Last reply
    0
    • M MScottM

      Hi @JKSH,

      I removed the '&' and got the same result - "no such signal".

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #12

      @mscottm said in Signal not emitted or not received:

      I removed the '&' and got the same result - "no such signal".

      Looking at your mainWindow.h, you don't have a analogInputsValue() signal. Instead, you have a analogInputsValue(QString, qint16, qint16, qint16, qint16) signal.

      So, your connection code should be
      connect(this, SIGNAL(analogInputsValue(QString, qint16, qint16, qint16, qint16)), qApp, SLOT(aboutQt()));

      NOTE: Remember the () in the slot too! Write SLOT(aboutQt()), not SLOT(aboutQt)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      3
      • M Offline
        M Offline
        MScottM
        wrote on last edited by
        #13

        @jksh said in Signal not emitted or not received:

        connect(this, SIGNAL(analogInputsValue(QString, qint16, qint16, qint16, qint16)), qApp, SLOT(aboutQt()));

        OHHH! That did it, thanks!

        So the signal is obviously firing - the 'About' message box popped up. Now I know where to focus my troubleshooting. I know that at least the IDE is recognizing the class contextProperty, as it 'colorizes' the target class name in the connect statement.

        What else can I look at or try?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #14

          Well, to ensure that the basics are working, try starting from the Embedding C++ Objects into QML with Context Properties example and then move things around until they are where you would like to have them in your application.

          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
          • M Offline
            M Offline
            MScottM
            wrote on last edited by
            #15

            @SGaist - on that page it says:

            "If the QML item needs to receive signals from the context property, it can connect to them using the Connections type. For example, if ApplicationData has a signal named dataChanged(), this signal can be connected to using an onDataChanged handler within a Connections object:

            Text {
                text: applicationData.getCurrentDateTime()
            
                Connections {
                    target: applicationData
                    onDataChanged: console.log("The application data changed!")
                }
            }
            

            That is what I'm doing, and the only difference from my QML and their example is I have my Connections statement higher in the hierarchy, but I've tried it in multiple places.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #16

              What I wanted you to check was that your QML + context properties are working correctly when following the same setup as the example provided in the documentation. Once that has been confirmed, we can then move these stuff in your main window class.

              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
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #17

                The code you posted is very large; it will take us a lot of time to read through and identify your problem.

                Please post a minimal example that demonstrates your problem.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  MScottM
                  wrote on last edited by MScottM
                  #18

                  Hi @SGaist,

                  I think you put me on to something. When I created the project to test the code in the example you pointed to, I noticed in the 'boilerplate' code that was created, a QObject::connect statement that I don't have:

                  QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                                       &app, [url](QObject *obj, const QUrl &objUrl) {
                          if (!obj && url == objUrl)
                              QCoreApplication::exit(-1);
                      }, Qt::QueuedConnection);
                      engine.load(url);
                  

                  Is this connecting the qml side to the cpp side? I didn't think about this as I was adapting an example. Do I need to add something like this?

                  edit - I also just noticed that there is a QQmlApplicationEngine created in the main.cpp, and I created another one in MainWindow.cpp - that has to be an issue...doesn't it?

                  @JKSH - I do apologize, I was trying to be thorough, but I understand the need for brevity when someone is trying to help and get to the heart of an issue.

                  1 Reply Last reply
                  1
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    It can be useful to stop the application if there's a failure to create the object from the file you passed as parameter.

                    It is however not directly related to the issue you are having.

                    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
                    • M Offline
                      M Offline
                      MScottM
                      wrote on last edited by
                      #20

                      Hi @SGaist ,

                      I created a small project and adapted the example you pointed to, and created a signal in c++ that would update a text in QML every few seconds using context properties and a Connections statement in QML:

                          QTimer* timer = new QTimer(this);
                                  timer->setInterval(3000);
                                  connect(timer, SIGNAL(timeout()),
                                          this, SLOT(sendOutSignal()));
                                  timer->start();
                      }
                      void pMessageProcessor::sendOutSignal() {
                           x+=1;
                          number.setNum(x);
                          emit mySignal(number);
                      }
                      
                      Text {
                              id: myText
                              text: {""}
                      
                              Connections {
                                  target: applicationData
                                  onMySignal: myText.text = myVariable
                              }
                          }
                      

                      It works as expected.

                      Next I moved the code over to my application and connected one of my QML label texts to the signal and it works - the label updates with the timer and signal, however I still can't get my original signal to work.

                      JKSHJ 1 Reply Last reply
                      2
                      • M MScottM

                        Hi @SGaist ,

                        I created a small project and adapted the example you pointed to, and created a signal in c++ that would update a text in QML every few seconds using context properties and a Connections statement in QML:

                            QTimer* timer = new QTimer(this);
                                    timer->setInterval(3000);
                                    connect(timer, SIGNAL(timeout()),
                                            this, SLOT(sendOutSignal()));
                                    timer->start();
                        }
                        void pMessageProcessor::sendOutSignal() {
                             x+=1;
                            number.setNum(x);
                            emit mySignal(number);
                        }
                        
                        Text {
                                id: myText
                                text: {""}
                        
                                Connections {
                                    target: applicationData
                                    onMySignal: myText.text = myVariable
                                }
                            }
                        

                        It works as expected.

                        Next I moved the code over to my application and connected one of my QML label texts to the signal and it works - the label updates with the timer and signal, however I still can't get my original signal to work.

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #21

                        @mscottm said in Signal not emitted or not received:

                        Next I moved the code over to my application and connected one of my QML label texts to the signal and it works - the label updates with the timer and signal, however I still can't get my original signal to work.

                        Congratulations, that's good progress.

                        Compare the two applications and see what's different between the way your C++ and QML objects are set up. This will lead you to the solution. It might help if you start removing parts from your original application that are not related to the connection.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        1
                        • M Offline
                          M Offline
                          MScottM
                          wrote on last edited by
                          #22

                          Sorry to dig this up again, but I've been banging my head against this for more than two weeks now, and I can't figure this out. THIS SHOULD WORK!!

                          The only time I can get the QML to react to a c++ signal is when it is called by my test timer:

                              QTimer* timer = new QTimer(this);
                                      timer->setInterval(3000);
                          
                          
                                      connect(timer, SIGNAL(timeout()),
                                              this, SLOT(sendOutSignal()));
                          
                                      timer->start();
                          }
                          
                          void pMessageProcessor::sendOutSignal() {
                               x+=1;
                              number.setNum(x);
                              emit mySignal(number);
                              qDebug() << "mySignal emitted" << number;
                          }
                          

                          and I see QML console.log messages that the signal was received, and labels that are tied to the data update accordingly

                          When I try ANY other way to get my signal to QML, it doesn't work. I've tried SO MANY other ways to send the signal that I've lost track of what I've done so far...NOTHING WORKS. Sorry, my frustration is leaking out.

                          // Working Signal
                          void mySignal(const QString& myVariable);
                          
                          // Non-Working Signal
                          void srcAddressOut(const QString& sourceAddressOut);
                          
                          // Working emit
                          emit mySignal(number);
                          
                          // Non-Working emit
                          emit srcAddressOut(_srcAddress);
                          

                          (but I've proven this signal IS emitting)

                          // Working QML receiver
                          onMySignal: { console.log(myVariable); statusMessages2.text = myVariable; }
                          
                          // Non-Working QML receiver
                          onSrcAddressOut: { console.log(sourceAddressOut); statusMessages2.text = sourceAddressOut; }
                          

                          what is different???

                          JKSHJ 1 Reply Last reply
                          0
                          • M MScottM

                            Sorry to dig this up again, but I've been banging my head against this for more than two weeks now, and I can't figure this out. THIS SHOULD WORK!!

                            The only time I can get the QML to react to a c++ signal is when it is called by my test timer:

                                QTimer* timer = new QTimer(this);
                                        timer->setInterval(3000);
                            
                            
                                        connect(timer, SIGNAL(timeout()),
                                                this, SLOT(sendOutSignal()));
                            
                                        timer->start();
                            }
                            
                            void pMessageProcessor::sendOutSignal() {
                                 x+=1;
                                number.setNum(x);
                                emit mySignal(number);
                                qDebug() << "mySignal emitted" << number;
                            }
                            

                            and I see QML console.log messages that the signal was received, and labels that are tied to the data update accordingly

                            When I try ANY other way to get my signal to QML, it doesn't work. I've tried SO MANY other ways to send the signal that I've lost track of what I've done so far...NOTHING WORKS. Sorry, my frustration is leaking out.

                            // Working Signal
                            void mySignal(const QString& myVariable);
                            
                            // Non-Working Signal
                            void srcAddressOut(const QString& sourceAddressOut);
                            
                            // Working emit
                            emit mySignal(number);
                            
                            // Non-Working emit
                            emit srcAddressOut(_srcAddress);
                            

                            (but I've proven this signal IS emitting)

                            // Working QML receiver
                            onMySignal: { console.log(myVariable); statusMessages2.text = myVariable; }
                            
                            // Non-Working QML receiver
                            onSrcAddressOut: { console.log(sourceAddressOut); statusMessages2.text = sourceAddressOut; }
                            

                            what is different???

                            JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by JKSH
                            #23

                            @mscottm said in Signal not emitted or not received:

                            When I try ANY other way to get my signal to QML, it doesn't work. I've tried SO MANY other ways to send the signal that I've lost track of what I've done so far...NOTHING WORKS.

                            Can you post a compilable example of what you've tried? (Try to keep the code minimal) We can look through the code for you.

                            Anyway, here's a different technique that does work: https://doc.qt.io/qt-5/signalsandslots-syntaxes.html#connecting-c-objects-to-qml-objects (It makes the connection on the C++ side rather than the QML side)

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            3
                            • M Offline
                              M Offline
                              MScottM
                              wrote on last edited by
                              #24

                              @JKSH - regarding posting my code - I think I can pare down the code I've added to the example, but I don't think I could figure out what to cut from the example code, and maybe how I integrated it is part of the issue...? Would it be okay to just post the pared down part that I added to the example code?

                              JKSHJ 1 Reply Last reply
                              0
                              • M MScottM

                                @JKSH - regarding posting my code - I think I can pare down the code I've added to the example, but I don't think I could figure out what to cut from the example code, and maybe how I integrated it is part of the issue...? Would it be okay to just post the pared down part that I added to the example code?

                                JKSHJ Offline
                                JKSHJ Offline
                                JKSH
                                Moderators
                                wrote on last edited by
                                #25

                                @mscottm said in Signal not emitted or not received:

                                I think I can pare down the code I've added to the example, but I don't think I could figure out what to cut from the example code, and maybe how I integrated it is part of the issue...? Would it be okay to just post the pared down part that I added to the example code?

                                Sure, go ahead.

                                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  MScottM
                                  wrote on last edited by
                                  #26

                                  @JKSH

                                  Okay - I wasted another week and a half trying to solve this myself with no result :(

                                  Not sure how to pass along my minimized code - is there a way to attach a zip? Even though it's shortened, it seems like a lot to paste here.

                                  mrjjM JKSHJ 2 Replies Last reply
                                  0
                                  • M MScottM

                                    @JKSH

                                    Okay - I wasted another week and a half trying to solve this myself with no result :(

                                    Not sure how to pass along my minimized code - is there a way to attach a zip? Even though it's shortened, it seems like a lot to paste here.

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by mrjj
                                    #27

                                    @MScottM
                                    Hi
                                    The upload here is not so cooperative with zip files.
                                    alt text

                                    So you have to use some upload service (google drive, pcloud or similar)
                                    that can give an URL to paste here.
                                    https://wetransfer.com/ can also do it with no install
                                    if you swich to "send as link" mode.
                                    using the the round [...] button.

                                    1 Reply Last reply
                                    1
                                    • M MScottM

                                      @JKSH

                                      Okay - I wasted another week and a half trying to solve this myself with no result :(

                                      Not sure how to pass along my minimized code - is there a way to attach a zip? Even though it's shortened, it seems like a lot to paste here.

                                      JKSHJ Offline
                                      JKSHJ Offline
                                      JKSH
                                      Moderators
                                      wrote on last edited by JKSH
                                      #28

                                      @MScottM said in Signal not emitted or not received:

                                      Not sure how to pass along my minimized code - is there a way to attach a zip?

                                      Like @mrjj said, upload your zip file to an external file host and post the link here.

                                      Okay - I wasted another week and a half trying to solve this myself with no result :(
                                      ...
                                      Even though it's shortened, it seems like a lot to paste here.

                                      Thank you for making the effort. Upload the zip file containing your whole project (so that I can just click "build" and run it -- it doesn't matter if I need a CAN bus device); I'm happy to look through your work.

                                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                      1 Reply Last reply
                                      2
                                      • M Offline
                                        M Offline
                                        MScottM
                                        wrote on last edited by MScottM
                                        #29

                                        Here is the link to a zip file:

                                        https://we.tl/t-jlLJoUCTvs

                                        Notes:
                                        There is a text file needed (included in file) that goes into the build folder. Steps to test my non-working signal (in pMessageProcessor.cpp):

                                        CAN cable isn't needed - on running the program:
                                        Select 'virtualcan' from drop down
                                        Check 'Custom Configuration' and set 'Receive Own' to True - click OK
                                        At menu on top click Monitor -> P Bus
                                        In center box click 'Module 1'

                                        (Back to Can Example Window)
                                        Check 'Extended Format' and in the 'Frame ID' box type FF0400
                                        In the 'Payload' box type eight bytes, i.e. 11 22 33 44 55 66 77 88 and send

                                        Thank you for taking the time to take a look!

                                        JKSHJ 1 Reply Last reply
                                        0
                                        • M MScottM

                                          Here is the link to a zip file:

                                          https://we.tl/t-jlLJoUCTvs

                                          Notes:
                                          There is a text file needed (included in file) that goes into the build folder. Steps to test my non-working signal (in pMessageProcessor.cpp):

                                          CAN cable isn't needed - on running the program:
                                          Select 'virtualcan' from drop down
                                          Check 'Custom Configuration' and set 'Receive Own' to True - click OK
                                          At menu on top click Monitor -> P Bus
                                          In center box click 'Module 1'

                                          (Back to Can Example Window)
                                          Check 'Extended Format' and in the 'Frame ID' box type FF0400
                                          In the 'Payload' box type eight bytes, i.e. 11 22 33 44 55 66 77 88 and send

                                          Thank you for taking the time to take a look!

                                          JKSHJ Offline
                                          JKSHJ Offline
                                          JKSH
                                          Moderators
                                          wrote on last edited by JKSH
                                          #30

                                          @MScottM OK, I've downloaded your code and am looking through it. I will probably post back in the next day or two.

                                          In the meantime, I've got a few questions:

                                          1. You have two different instances of pMessageProcessor in your code (one is a member variable in MainWindow, the other is in your main.cpp). Which one did you intend to use? (Similarly, you have 2 different instances of QQmlEngine)
                                            • An important part of minimizing your code for troubleshooting is to get rid of unneeded objects.
                                          2. You mentioned that this is a "learning project". Could you describe what you're focussing on learning?
                                            • Is it learning to use Qt's CAN classes? Learning to integrate C++ and QML? Learning how to create GUIs in QML? A combination of the above? Something else completely?

                                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                          1 Reply Last reply
                                          4

                                          • Login

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