Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-127583

QML tools: Detect and warn about potential naming errors in QML Connections

    XMLWordPrintable

Details

    Description

      Code

      import QtQuick
      
      Window {
          width: 800
          height: 600
          visible: true
      
          QtObject {
              id: myObj
              signal mySignal()
      
              onMySignal: console.log("Ding!")
              onMySignall: console.log("Dong!") // WARNING: no matching signal found for handler "onMySignall" [unqualified]
          }
      
          Connections {
              target: myObj
              function onMySignal() {
                  console.log("Ding!")
              }
              function onMySignall() { // No edit-/build-time warning
                  console.log("Dong!")
              }
          }
      
          Component.onCompleted: myObj.mySignal()
      }
      

       

      Outcomes
      (Expected) qmlls, qmllint, and qmlsc all warn about the mis-spelt declarative signal handler:

      no matching signal found for handler "onMySignall" [unqualified]
              onMySignall: console.log("Dong!")
              ^^^^^^^^^^^
      

       

      (Not Expected) No such warnings are provided for the mis-spelt Connections function during edit-/build-time. We only get a runtime warning:

      QML Connections: Detected function "onMySignall" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.
      

       

      Suggestions

      • QML tools should apply the same heuristics as the runtime engine. If a Connection's target's list of signals is known, and a function in that Connections has a name that starts with "on", but no matching signal in the target, then flag it.
      • Bonus: Also flag if the parameter lists are incompatible

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            skoh-qt Sze Howe Koh
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes