Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Types registered with qmlRegisterUncreatableType not available for properties
thorbjorn last edited by thorbjorn
I'm trying to register a custom QML type that should not be created from QML, but I would really like to define properties with that type, mostly for the purposes of clarity and code completion. Unfortunately, it looks like types registered with
qmlRegisterUncreatableTypeare not even available as properties:
qmlRegisterUncreatableType<Model>("Model", 1, 0, "Model", "Model is created natively");
And then doing this in QML:
property Model model: null;
Leads to the error "Model is created natively". But it does not make sense to me, since the above line is not trying to create an instance.
Is this intentional or a possible bug in Qt?
Taking a look at the attribute property documentation it makes sense that the type used for a property must be "creatable". A QML property implies the same rules as the
Q_PROPERTYyou'd use on the C++ side.
thorbjorn last edited by
@SGaist Hmm, but doesn't this translate to a pointer property? I'd expect the mapping to be:
property string s; property Model m; Q_PROPERTY(QString s ...) Q_PROPERTY(Model *m ...)
And the second really doesn't imply that
Modelneeds to be creatable from QML. That would only be the case if I wrote this: