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

Import with qualifier breaks enums for ListElement

    XMLWordPrintable

    Details

    • Commits:
      a363aa3df44da399d2aeb8785608501eae50e600 (qt/qtdeclarative/5.15)

      Description

      When using a qualifier on an import in QML, it breaks the ListElement's ability to use a C++ enum, producing the error:

      "ListElement: cannot use script for property value"

       

      Minimal example:

      EnumTester.h

       

      #ifndef ENUMTESTER_H
      #define ENUMTESTER_H
      #include <QObject>
      
      class EnumTester : public QObject
      {
          Q_OBJECT
      public:
          enum Types
          {
              FIRST = 0,
              SECOND,
              THIRD
          };
          Q_ENUM(Types)
      };
      #endif // ENUMTESTER_H
      

      main.qml

       

       

      import QtQuick 2.12
      
      import bug.test 1.0 as BACKEND
      //import bug.test 1.0
      
      Item {
          ListModel {
              ListElement{ text: qsTr("First"); type: BACKEND.EnumTester.FIRST }
      //        ListElement{ text: qsTr("First"); type: EnumTester.FIRST }
          }
      }
      

      main.cpp

       

       

      #include "EnumTester.h"
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
          QGuiApplication app(argc, argv);
      
          qmlRegisterUncreatableType<EnumTester>("bug.test", 1, 0, "EnumTester", "Object only creatable in C++");
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
              &app, [url](QObject *obj, const QUrl &objUrl) {
                  if (!obj && url == objUrl)
                      QCoreApplication::exit(-1);
              }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      
      

       

      Swapping the commented lines in the QML to remove the qualifier and the Item loads fine.

       

        Attachments

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

          Activity

            People

            Assignee:
            ulherman Ulf Hermann
            Reporter:
            emagnuson Eric Magnuson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes