Enumerations in uncreatable types with lowercase name
-
Hi,
i'm not able to acces my enumerations of an uncreatable type if the name is lowercase.myclass.h
class MyClass { Q_GADGET public: enum MyEnum { Value1, Value2 }; Q_ENUM(MyEnum) }
main.cpp
int main(int argc, char *argv[]) { qRegisterUncreatableType<MyClass>("my.company", 1, 0, "MyClass"); // qt.qml.typeregistration: Invalid QML element name "MyClass"; value type names should begin with a lowercase letter qRegisterUncreatableType<MyClass>("my.company", 1, 0, "myClass"); QQmlApplicationEngine engine; engine.load(QUrl(QLatin1String("qrc:/main.qml"))); }
main.qml
import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import my.company1.0 ApplicationWindow { Component.onCompleted: { console.log(MyClass.Value1) // works console.log(myClass.Value1) // ReferenceError: myClass is not defined } }
-
This is a bit awkward for the moment and I'm not convinced by the way it should be done currently.
You can addpragma ValueTypeBehavior: Addressable
at the top of a QML file to be able to refer to value types and then your latter snippet would work.
For reference (the last comment by Ulf): https://bugreports.qt.io/browse/QTBUG-88008?focusedId=712036&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-712036 -
@GrecKo said in Enumerations in uncreatable types with lowercase name:
pragma ValueTypeBehavior: Addressable
leads to
error: Unknown value type behavior 'Addressable' in pragma
I'm working with Qt6.5: only Copy and Reference values for the ValueTypeBehavior pragma are experimental options. And both do not work.
-
This pragma was added in Qt 6.6 : https://doc.qt.io/qt-6/qtqml-documents-definetypes.html#valuetypebehavior