Important: Please read the Qt Code of Conduct -

Types registered with qmlRegisterUncreatableType not available for properties

  • 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 qmlRegisterUncreatableType are 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?

  • Lifetime Qt Champion


    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.

  • @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 Model needs to be creatable from QML. That would only be the case if I wrote this:

    Model {}

Log in to reply