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

qmllint/qmlsc fails to recognize Q_INVOKABLE function parameters of enum type unless fully qualified in signature

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.10
    • 6.8.3, 6.8.4
    • QML: Compiler, QML: Tooling
    • None

    Description

      When using qmllint on a QML application that calls a C++ Q_INVOKABLE method with a parameter of an enum type declared within the class, qmllint issues a warning about argument count/type if the enum type in the method signature is not fully qualified with the class name. 

      If the C++ method is declared as:

       

      class MyItem : public QObject {
          Q_OBJECT
      public:
          enum Operation {
              Normal,
              Immediate
          };
          Q_ENUM(Operation)
          Q_INVOKABLE void doSomething(Operation op = Normal) { /* ... */ }
      };
      

      Then a QML call like:

      MyItem { id: item }
      Component.onCompleted: item.doSomething(MyItem.Immediate)

      generates a warning:

      Function expects 0 arguments, but 1 were provided type Operation for argument 0 cannot be resolved [compiler]

      When the method is declared as:

      Q_INVOKABLE void doSomething(MyItem::Operation op = MyItem::Normal);

      The warning goes away.

      This issue is not limited to user-defined types: it also affects several built-in QtQuick QML types such as StackView and TableView. For example, methods like StackView.popToItem(item, StackView.Immediate) and TableView.positionViewAtRow(row, TableView.Visible, 0.0) will trigger similar warnings from qmllint.

      Attachments

        1. TestInvokable.txt
          2 kB
          Romain Donzé
        2. TestInvokable.zip
          3 kB
          Romain Donzé
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            romain.donze Romain Donzé
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes