Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
5.14.0, 5.15.1
-
Linux Mint 19.3
Description
When I use using-declared enum as a property type in another class then the property isn't compared correctly with the enum value in QML.
enum class
class GradesClass { Q_GADGET public: enum GradesEnum { A = 0, B, C }; Q_ENUM(GradesEnum) ... }; using Grade = GradesClass::GradesEnum;
other class
class Student : public QObject { Q_OBJECT public: ... Q_PROPERTY(Grade grade READ grade NOTIFY gradeChanged) Grade grade() { return m_grade; } ... Grade m_grade = Grade::B; };
main.cpp
qRegisterMetaType<Grade>("Grade"); engine.rootContext()->setContextProperty("student", new Student()); qmlRegisterUncreatableType<GradesClass>("App.Grades", 1, 0, "Grades", "...");
main.qml
import App.Grades 1.0 Window { visible: true Component.onCompleted: { console.log("student.grade:", student.grade) console.log("Enum value:", Grades.B) console.log("Equals enum val:", (student.grade === Grades.B)) console.log("Equals int:", (student.grade === 1)) } }
output
qml: student.grade: B qml: Enum value: 1 qml: Equals enum val: false qml: Equals int: false
If NOT using using-declaration for enum Q_PROPERTY it works as expected:
Q_PROPERTY(GradesClass::GradesEnum grade READ grade NOTIFY gradeChanged)
output
qml: student.grade: 1 qml: Enum value: 1 qml: Equals enum val: true qml: Equals int: true