Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.4
-
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.