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. QML Warnings

QML Warnings

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 959 Views
  • 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.
  • V Offline
    V Offline
    Veltroniv
    wrote on last edited by
    #1

    **Hello everyone,

    I'm currently facing some warnings while compiling my QML application, and I'm not quite sure how to resolve them. Here are the warnings I'm getting:

    qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginFailed"
    qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginCorrect"
    qml/pages/LoginPage.qml:21: ReferenceError: g_apiManager is not defined
    qml/pages/LoginPage.qml:22:5 Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
    

    Here's the relevant code snippet from LoginPage.qml:

    function loginCorrectHandler(token) {
      console.log("Token:", token)
    }
    
    Connections {
      target: g_apiManager
      onLoginCorrect: {
        loginCorrectHandler(token)
      }
      onLoginFailed: {
        console.log("Login failed")
      }
    }
    

    And here's the corresponding C++ code:

    Q_INVOKABLE void loginCorrect(const QString& token);
    Q_INVOKABLE void loginFailed();
    

    main.cpp

        ApiManager g_apiManager;
        engine.rootContext()->setContextProperty("g_apiManager", &g_apiManager);
    

    Everything works perfectly fine, but i dont know how to get rid of these warnings.
    Could anyone please help me understand how to resolve these warnings?

    Thank you in advance for your help!

    JoeCFDJ 1 Reply Last reply
    0
    • V Veltroniv

      **Hello everyone,

      I'm currently facing some warnings while compiling my QML application, and I'm not quite sure how to resolve them. Here are the warnings I'm getting:

      qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginFailed"
      qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginCorrect"
      qml/pages/LoginPage.qml:21: ReferenceError: g_apiManager is not defined
      qml/pages/LoginPage.qml:22:5 Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
      

      Here's the relevant code snippet from LoginPage.qml:

      function loginCorrectHandler(token) {
        console.log("Token:", token)
      }
      
      Connections {
        target: g_apiManager
        onLoginCorrect: {
          loginCorrectHandler(token)
        }
        onLoginFailed: {
          console.log("Login failed")
        }
      }
      

      And here's the corresponding C++ code:

      Q_INVOKABLE void loginCorrect(const QString& token);
      Q_INVOKABLE void loginFailed();
      

      main.cpp

          ApiManager g_apiManager;
          engine.rootContext()->setContextProperty("g_apiManager", &g_apiManager);
      

      Everything works perfectly fine, but i dont know how to get rid of these warnings.
      Could anyone please help me understand how to resolve these warnings?

      Thank you in advance for your help!

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @Veltroniv said in QML Warnings:

      Q_INVOKABLE void loginCorrect(const QString& token);
      Q_INVOKABLE void loginFailed();

      these funcs are not signals. your Connections treat them as signals.

      Q_INVOKABLE void loginCorrect(const QString& token);
      Q_INVOKABLE void loginFailed();
      
      V 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @Veltroniv said in QML Warnings:

        Q_INVOKABLE void loginCorrect(const QString& token);
        Q_INVOKABLE void loginFailed();

        these funcs are not signals. your Connections treat them as signals.

        Q_INVOKABLE void loginCorrect(const QString& token);
        Q_INVOKABLE void loginFailed();
        
        V Offline
        V Offline
        Veltroniv
        wrote on last edited by
        #3

        @JoeCFD
        so is any option to remove those warnings? in my cpp.h i declared them as signals.

        signals:
           Q_INVOKABLE void loginCorrect(const QString& token);
           Q_INVOKABLE void loginFailed();
        

        or it is what it is ?

        JoeCFDJ B 2 Replies Last reply
        0
        • V Veltroniv

          @JoeCFD
          so is any option to remove those warnings? in my cpp.h i declared them as signals.

          signals:
             Q_INVOKABLE void loginCorrect(const QString& token);
             Q_INVOKABLE void loginFailed();
          

          or it is what it is ?

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @Veltroniv
          ReferenceError: g_apiManager is not defined

          show more code about

              ApiManager g_apiManager;
              engine.rootContext()->setContextProperty("g_apiManager", &g_apiManager);
          

          Bob64 is right. If the funcs are signals, Q_INVOKABLE is not needed.

          1 Reply Last reply
          0
          • V Veltroniv

            @JoeCFD
            so is any option to remove those warnings? in my cpp.h i declared them as signals.

            signals:
               Q_INVOKABLE void loginCorrect(const QString& token);
               Q_INVOKABLE void loginFailed();
            

            or it is what it is ?

            B Offline
            B Offline
            Bob64
            wrote on last edited by
            #5

            @Veltroniv remove Q_INVOKABLE. Marking a function as Q_INVOKABLE makes it callable from QML, so you would expect to use it like this in QML code:

            g_apiManager.loginCorrect("token");
            

            Q_INVOKABLE is more like making a function a slot.

            V 1 Reply Last reply
            0
            • B Bob64

              @Veltroniv remove Q_INVOKABLE. Marking a function as Q_INVOKABLE makes it callable from QML, so you would expect to use it like this in QML code:

              g_apiManager.loginCorrect("token");
              

              Q_INVOKABLE is more like making a function a slot.

              V Offline
              V Offline
              Veltroniv
              wrote on last edited by Veltroniv
              #6

              @Bob64, I changed the placement of the engine.rootContext(...) line, moving it after the initialization of engine. Now, I don't get such errors. I placed it before the
              felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));line, and it works. The warnings disappear.

              I'm left with only one warning now:

              Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
              

              So, I emit the signal from C++ as emit LoginCorrect(token), and I'm trying to catch that in QML by:

              
                function loginCorrectHandler(token) {
                  console.log("Token:", token)
                }
              
                Connections {
                  target: g_apiManager
                  onLoginCorrect: {
                    loginCorrectHandler(token)
                  }
                  onLoginFailed: {
                    console.log("Login failed")
                  }
                }
              

              It's pointing out that I'm using deprecated functions. How should I do it correctly?

              //EDIT
              That was quite easy, i did it by:

                  onLoginCorrect: function (token) {
                    console.log("Token:", token)
                  }
              

              Correct me if im wrong. Thanks :)

              GrecKoG 1 Reply Last reply
              0
              • V Veltroniv has marked this topic as solved on
              • V Veltroniv

                @Bob64, I changed the placement of the engine.rootContext(...) line, moving it after the initialization of engine. Now, I don't get such errors. I placed it before the
                felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));line, and it works. The warnings disappear.

                I'm left with only one warning now:

                Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
                

                So, I emit the signal from C++ as emit LoginCorrect(token), and I'm trying to catch that in QML by:

                
                  function loginCorrectHandler(token) {
                    console.log("Token:", token)
                  }
                
                  Connections {
                    target: g_apiManager
                    onLoginCorrect: {
                      loginCorrectHandler(token)
                    }
                    onLoginFailed: {
                      console.log("Login failed")
                    }
                  }
                

                It's pointing out that I'm using deprecated functions. How should I do it correctly?

                //EDIT
                That was quite easy, i did it by:

                    onLoginCorrect: function (token) {
                      console.log("Token:", token)
                    }
                

                Correct me if im wrong. Thanks :)

                GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #7

                @Veltroniv the preferred Connections syntax is now:

                Connections {
                    function onLoginCorrect(token) {
                        console.log("Token: ", token);
                    }
                }
                
                1 Reply Last reply
                1

                • Login

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