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

qmllint - false-positive unqualified access warning with enums in Q_GADGETs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • 6.5
    • 6.5.2
    • QML: Tooling
    • None

    Description

      The code below was the recommended way to define enums in Q_GADGET's that can be used in QML. However, with this setup qmllint is incorrectly (I believe) issuing a warning for unqualified access.

      The C++ types are defined as follows:

       

      #ifndef TYPES_H
      #define TYPES_H
      
      #include <QtQml/QtQml>
      
      //----------------------------------------------------------------------//
      struct TestGadget
      {
          Q_GADGET
          QML_NAMED_ELEMENT(testGadget)
      
          Q_PROPERTY(int value MEMBER value)
      
      public:
          enum class GadgetEnum
          {
              OptionA,
              OptionB,
              OptionC,
          };
          Q_ENUM(GadgetEnum)
      
      public:
          int value = 0;
      };
      
      struct TestGadgetDerived : TestGadget
      {
          Q_GADGET
      };
      
      namespace TestGadgetEnums
      {
          Q_NAMESPACE
          QML_FOREIGN_NAMESPACE(TestGadgetDerived)
          QML_NAMED_ELEMENT(TestGadget)
      } // namespace TestGadgetEnums
      
      #endif

       

       

      QML:

       

      ...
      Component.onCompleted: {
        console.log("TestGadget.GadgetEnum.OptionC = " + TestGadget.GadgetEnum.OptionC)
      }
      ...

       

       

      qmllint generates the following warning:

      app_test_qml_application.qml:117:54: warning: Unqualified access [unqualified]
                      console.log("TestGadget.GadgetEnum.OptionC = " + TestGadget.GadgetEnum.OptionC)
                                                                       ^^^^^^^^^^

       

      I am seeing this with a skeleton project in QtCreator

      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
            matthewf.za Matthew Fincham
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes