Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt5.12.3: C++ signal -> QML slot
Qt 6.11 is out! See what's new in the release blog

Qt5.12.3: C++ signal -> QML slot

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
25 Posts 5 Posters 13.6k 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.
  • M Offline
    M Offline
    Melle_87
    wrote on last edited by Melle_87
    #1

    Hi all,

    I have just upgraded from Qt5.9 to Qt5.12.3.
    Now I get some errors when I am compiling my application with the new Qt version.

    I am sending signals from C++ and receive them in slots in QML. I am sending to parameters with these signals.
    Now I get a reference error, that is telling me that this variable (parameter of my signal) is not defined.

    ReferenceError: name is not defined
    

    Here a little example:

    C++:

    class TestClass: public QObject
    {
        Q_OBJECT
    
        public: ...
        protected: ...
        private: ...
        signals: void propertyChanged(QString name, QString val);
        private slots: ...
    };
    

    QML:

    Connections {
            target: TestClass
            onPropertyChanged: {
                if (name == "testStr") {
                }
                ...
            }
    }
    

    Any ideas?
    How can I send a parameter with signal / slot from C++ to QML?

    Kind regards,
    Melle_87

    B 1 Reply Last reply
    0
    • M Melle_87

      Hi all,

      I have just upgraded from Qt5.9 to Qt5.12.3.
      Now I get some errors when I am compiling my application with the new Qt version.

      I am sending signals from C++ and receive them in slots in QML. I am sending to parameters with these signals.
      Now I get a reference error, that is telling me that this variable (parameter of my signal) is not defined.

      ReferenceError: name is not defined
      

      Here a little example:

      C++:

      class TestClass: public QObject
      {
          Q_OBJECT
      
          public: ...
          protected: ...
          private: ...
          signals: void propertyChanged(QString name, QString val);
          private slots: ...
      };
      

      QML:

      Connections {
              target: TestClass
              onPropertyChanged: {
                  if (name == "testStr") {
                  }
                  ...
              }
      }
      

      Any ideas?
      How can I send a parameter with signal / slot from C++ to QML?

      Kind regards,
      Melle_87

      B Offline
      B Offline
      Boaschtel
      wrote on last edited by
      #2

      I was about to post about the same topic, as I am encountering the same issue.
      Can you confirm that you are using similar settings:

      MSVC 2017 32bit
      Compiling in debug mode.
      Launching via the debugger.

      For me everything works as expected when launching via "Run".

      Cheers!

      M 1 Reply Last reply
      0
      • B Boaschtel

        I was about to post about the same topic, as I am encountering the same issue.
        Can you confirm that you are using similar settings:

        MSVC 2017 32bit
        Compiling in debug mode.
        Launching via the debugger.

        For me everything works as expected when launching via "Run".

        Cheers!

        M Offline
        M Offline
        Melle_87
        wrote on last edited by
        #3

        @Boaschtel:

        Thanks for your answer.
        I am cross compiling on Ubuntu for Raspberry Pi 3. (GCC)
        I am also compiling in debug mode and launching via the debugger.
        And yes you are right. If I am launching via "Run" then everyhing works as expected.

        Maybe someone already found a solution for this problem?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Boaschtel
          wrote on last edited by
          #4

          Well this takes MSVC and Windows out of the equation at least.
          I was briefly looking for a solution yesterday but were unable to find one.

          But now that you are able to reproduce it as well I feel like this might be worth a bug report depending on answers to come.

          1 Reply Last reply
          0
          • J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            I can't really confirm this.

            I've been working on a (new) QML/cpp project all week, (macOS and iOS) and did not run into this at all (Qt 5.12.3).

            Have you done a clean/rebuild (build folder deletion) since updating ?

            Usually that shouldn't be needed as the new Qt version creates it own shadow build folder, depending on the version name.
            But it won't hurt to try, I guess.


            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.

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

              I can't really confirm this.

              I've been working on a (new) QML/cpp project all week, (macOS and iOS) and did not run into this at all (Qt 5.12.3).

              Have you done a clean/rebuild (build folder deletion) since updating ?

              Usually that shouldn't be needed as the new Qt version creates it own shadow build folder, depending on the version name.
              But it won't hurt to try, I guess.

              M Offline
              M Offline
              Melle_87
              wrote on last edited by
              #6

              @J.Hilk:

              Okay. Thanks.
              Yes. I already cleaned everything and built it new.
              Now, I deleted the build folder (as you suggested).
              But I am facing the same problem.

              If I am launching via "Start Debugging" I get these errors.
              If I am launching via "Run" everything seems to be okay.

              J.HilkJ 1 Reply Last reply
              0
              • M Melle_87

                @J.Hilk:

                Okay. Thanks.
                Yes. I already cleaned everything and built it new.
                Now, I deleted the build folder (as you suggested).
                But I am facing the same problem.

                If I am launching via "Start Debugging" I get these errors.
                If I am launching via "Run" everything seems to be okay.

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

                @Melle_87
                could you create a minimal compileable example, for others to test ?


                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.

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

                  @Melle_87
                  could you create a minimal compileable example, for others to test ?

                  M Offline
                  M Offline
                  Melle_87
                  wrote on last edited by
                  #8

                  @J.Hilk : I created a small example. But it is too big. I can not upload it here ...

                  ODБOïO 1 Reply Last reply
                  1
                  • M Melle_87

                    @J.Hilk : I created a small example. But it is too big. I can not upload it here ...

                    ODБOïO Offline
                    ODБOïO Offline
                    ODБOï
                    wrote on last edited by
                    #9

                    @Melle_87 hi
                    create one repo on github
                    https://help.github.com/en/articles/create-a-repo

                    M 1 Reply Last reply
                    1
                    • ODБOïO ODБOï

                      @Melle_87 hi
                      create one repo on github
                      https://help.github.com/en/articles/create-a-repo

                      M Offline
                      M Offline
                      Melle_87
                      wrote on last edited by
                      #10

                      @LeLev :
                      Okay. Now I created a repo on github.

                      link to example

                      Now this example is really stripped down to a minimum. Please don't ask for the sense of this project now. Because now it does not make sense anymore. But it demonstrates the error.

                      J.HilkJ 1 Reply Last reply
                      0
                      • M Melle_87

                        @LeLev :
                        Okay. Now I created a repo on github.

                        link to example

                        Now this example is really stripped down to a minimum. Please don't ask for the sense of this project now. Because now it does not make sense anymore. But it demonstrates the error.

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

                        @Melle_87 thanks,

                        I assume, in the example for your case, the background does not turn red ?
                        because it does for me, out of the box

                        0_1559030396560_736872ec-d7ab-4d4b-b992-185f29f3b90d-image.png

                        Qt 5.12.2
                        MacOS


                        edit:
                        same on windows, 5.12.2 as well I don't have a desktop 5.12.3 version. background turns red, either way, with or without debugger attached.


                        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.

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

                          @Melle_87 thanks,

                          I assume, in the example for your case, the background does not turn red ?
                          because it does for me, out of the box

                          0_1559030396560_736872ec-d7ab-4d4b-b992-185f29f3b90d-image.png

                          Qt 5.12.2
                          MacOS


                          edit:
                          same on windows, 5.12.2 as well I don't have a desktop 5.12.3 version. background turns red, either way, with or without debugger attached.

                          M Offline
                          M Offline
                          Melle_87
                          wrote on last edited by Melle_87
                          #12

                          @J.Hilk: Yes.
                          When I start the application out of Qt Creator via "Start debugging" the rectangle keeps blue and I get the error "ReferenceError: name is not defined".
                          If I start the application via "Run" the rectangle gets red and I get no errors.

                          As I mentioned before:
                          I am using Qt5.12.3. (Before I used Qt5.9.)
                          I am developing on Ubuntu and crosscompiling for Raspberry Pi 3.

                          Maybe in your case it is working because of your Qt5.12.2 version?

                          J.HilkJ 1 Reply Last reply
                          0
                          • M Melle_87

                            @J.Hilk: Yes.
                            When I start the application out of Qt Creator via "Start debugging" the rectangle keeps blue and I get the error "ReferenceError: name is not defined".
                            If I start the application via "Run" the rectangle gets red and I get no errors.

                            As I mentioned before:
                            I am using Qt5.12.3. (Before I used Qt5.9.)
                            I am developing on Ubuntu and crosscompiling for Raspberry Pi 3.

                            Maybe in your case it is working because of your Qt5.12.2 version?

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

                            @Melle_87 said in Qt5.12.3: C++ signal -> QML slot:

                            Maybe in your case it is working because of your Qt5.12.2 version?

                            maybe,
                            what are your debug settings, do you have qml debugging and profiling enabled ? do you use the QtQuickCompiler?


                            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.

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

                              @Melle_87 said in Qt5.12.3: C++ signal -> QML slot:

                              Maybe in your case it is working because of your Qt5.12.2 version?

                              maybe,
                              what are your debug settings, do you have qml debugging and profiling enabled ? do you use the QtQuickCompiler?

                              M Offline
                              M Offline
                              Melle_87
                              wrote on last edited by
                              #14

                              @J.Hilk: Yes.
                              Qml debugging is enabled. At application start I get: QML debugging is enabled. Only use this in a safe environment.
                              As debugger I am using: ~/raspi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gdb

                              1 Reply Last reply
                              1
                              • KroMignonK Offline
                                KroMignonK Offline
                                KroMignon
                                wrote on last edited by
                                #15

                                @Melle_87 said in Qt5.12.3: C++ signal -> QML slot:

                                Maybe in your case it is working because of your Qt5.12.2 version?

                                I've got same issue here with Windows XP7 64 and Qt5.12.3 32bit/MSVC2017:

                                • when starting in debug (F5) the window stays blue,
                                • when starting with "run" (Ctrl+R) the windows becomes red!

                                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
                                • J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  Well, I went and installed 5.12.3

                                  And loe and behold, the background stays blue. And the QML error appears in the console.

                                  since it works with 5.12.2 I would say this is a bug.

                                  You should open that bug report you mentioned. The minimal example will help speed that one up as well!

                                  You should post a link to the ticket, when you have. So others can find and follow it as well!


                                  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.

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

                                    Well, I went and installed 5.12.3

                                    And loe and behold, the background stays blue. And the QML error appears in the console.

                                    since it works with 5.12.2 I would say this is a bug.

                                    You should open that bug report you mentioned. The minimal example will help speed that one up as well!

                                    You should post a link to the ticket, when you have. So others can find and follow it as well!

                                    M Offline
                                    M Offline
                                    Melle_87
                                    wrote on last edited by Melle_87
                                    #17

                                    @J.Hilk:
                                    I created a bug report.
                                    link to bug report

                                    But nevertheless. If someone already has a solution or workaround for this problem I would be glad to know.

                                    KroMignonK 1 Reply Last reply
                                    1
                                    • M Melle_87

                                      @J.Hilk:
                                      I created a bug report.
                                      link to bug report

                                      But nevertheless. If someone already has a solution or workaround for this problem I would be glad to know.

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

                                      @Melle_87 Very strange, I've cleaned up a little bit the project:

                                      in pro file

                                      ...
                                      #QT += core gui serialport serialbus network sql qml quick widgets dbus multimedia multimediawidgets printsupport
                                      QT += core gui qml quick widgets printsupport
                                      ...
                                      

                                      in Main.qml

                                      import QtQuick 2.6
                                      import QtQuick.Window 2.3
                                      import QtQuick.Controls 1.4
                                      import "."
                                      
                                      ...
                                      

                                      Remove all build direction, rebuild all and now window is always red!?! in Release and Debug.

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

                                      J.HilkJ M 2 Replies Last reply
                                      0
                                      • KroMignonK KroMignon

                                        @Melle_87 Very strange, I've cleaned up a little bit the project:

                                        in pro file

                                        ...
                                        #QT += core gui serialport serialbus network sql qml quick widgets dbus multimedia multimediawidgets printsupport
                                        QT += core gui qml quick widgets printsupport
                                        ...
                                        

                                        in Main.qml

                                        import QtQuick 2.6
                                        import QtQuick.Window 2.3
                                        import QtQuick.Controls 1.4
                                        import "."
                                        
                                        ...
                                        

                                        Remove all build direction, rebuild all and now window is always red!?! in Release and Debug.

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

                                        @KroMignon
                                        you must have done more, as simply changing the pro file to only include those, still results in a blue background for me


                                        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.

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

                                          @KroMignon
                                          you must have done more, as simply changing the pro file to only include those, still results in a blue background for me

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

                                          @J.Hilk No, I've recheck with git-diff

                                          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

                                          • Login

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