Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QQmlListProperty is read only



  • Hello everyone,

    I created a class with a QQmlListProperty following exactly this example. But anytime I want to fill the list with values from qml (as they also did in this example), I get an error "property is read-only".
    From reading other Posts in the forum, it seems very likly that the the issue is that my type, which the QQmlListProperty stores, is not registered in qml.
    Well, I am using this in a plugin, so I made both classes (the class with QQmlListProperty, and the class stores in this list) available with qmlRegisterType.

    It's kind of hard to provide any source code, but I can't see any difference to the birthdayparty example except from the fact that it's a plugin.

    I appreciate any help!

    By the way, the birthdayparty example works.


  • Moderators

    @Leon_2001
    did you really exactly implemented it like in the example?
    the important line is:

    QQmlListProperty<Person>(this, this,
                 &BirthdayParty::appendGuest,
                 &BirthdayParty::guestCount,
                 &BirthdayParty::guest,
                 &BirthdayParty::clearGuests);
    

    If you leave out the BirthdayParty::appendGuest function pointer it will result in a read-only list.

    @Leon_2001 said in QQmlListProperty is read only:

    Well, I am using this in a plugin, so I made both classes (the class with QQmlListProperty, and the class stores in this list) available with qmlRegisterType.

    you may also use QML_DECLARE_TYPE



  • I tried to reproduce the problem without a plugin and I couldn't. That was the moment I realized, I forgot to make one class available to qml. It has pure virtual member functions, so qmlRegisterUncreatableType did the trick.

    @raven-worx When should I use QML_DECLARE_TYPE? (What's the difference except from the fact that it's a macro?)


  • Moderators

    @Leon_2001 said in QQmlListProperty is read only:

    When should I use QML_DECLARE_TYPE? (What's the difference except from the fact that it's a macro?)

    did you click on the link?


Log in to reply