Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved qmllint Qt 6.3.0 beta3 compile Type error on signal handler

    QML and Qt Quick
    1
    2
    133
    Loading More Posts
    • 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.
    • J
      jbrend last edited by jbrend

      Is there a way to write the signal handler (in this case, MouseArea.onWheel(WheelEvent wheel) so that the below noted qmllint warning regarding a type error is not raised?

      The code seems to otherwise work just fine.

      Environment: Qt 6.3.0 beta3 on Kubuntu Linux 21.10
      main.qml

      import QtQuick
      
      Text {
          id: root
          width: 200
          text: `exampleValue: ${exampleValue.toPrecision(4)}`
          horizontalAlignment: Text.AlignHCenter
          property real exampleValue: 3.0
          
          MouseArea {
              id: mouse
              anchors.fill: parent
              onWheel: function (wheel) {
                  root.exampleValue += root.exampleValue * (wheel.angleDelta.y / 1200) 
              }
          }
      }
      

      qmllint output:

      $ qmllint --compiler warning main.qml
      Info: main.qml:13:18: Could not compile binding for onWheel: Type error: could not infer the type of an expression
              onWheel: function (wheel) {
                       ^^^^^^^^^
      
      1 Reply Last reply Reply Quote 0
      • J
        jbrend last edited by jbrend

        Based on this presentation, it looks like the goal is to add support for TypeScript-like type annotations in order for the script to be compilable.

        How To Use QML in Qt6
        https://www.youtube.com/watch?v=4ji6D6UpA54
        32:53

        It seems like the detection tool (qmllint) is ahead of the language support because if I try that:

        onWheel: function (wheel: WheelEvent) {
            root.exampleValue += root.exampleValue * (wheel.angleDelta.y / 1200) 
        }
        

        I get this:

        $ qmllint --compiler warning main.qml
        main.qml:13:33: Type annotations are not permitted in function parameters in JavaScript functions
        

        ... and this (showing it's not just a spurious tool warning):

        $ qml main.qml
        QQmlApplicationEngine failed to load component
        file:///xxxx/Wheelies/main.qml:13:33: Type annotations are not permitted in function parameters in JavaScript functions
        qml: Did not load any objects, exiting.
        

        This page on qmllint does not state explicitly whether the tool is in Technical Preview as of Qt 6.3.0 beta3 or Qt 6.4.
        https://doc-snapshots.qt.io/qt6-dev/qtquick-tool-qmllint.html

        Neither does the tool's help.

        I found this in the interest@qt-project.org mailing list regarding adding type annotations. If I'm reading it correctly, support is already there, but qml cannot run the file with the type annotation as of Qt 6.3.0 beta3 (see above):
        https://codereview.qt-project.org/c/qt/qtdeclarative/+/249400

        Does anyone know more?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post