QML invalid property assignment - read-only property

  • I'm having trouble using the QMLListProperty class with my custom QML type. When I try to assign the following to the "vertices" list property:


    I get the error "Invalid property assignment: 'vertices' is a read-only property." The MapBrush class is a subclass of QObject and has Q_PROPERTY(QQmlListProperty<MapVertex> vertices READ vertices) declared as a property as per the documentation examples, and both (and more) are registered as QML types:

    qmlRegisterType<MapVertex>("crowbar.experiments.qml", 1, 0, "Vertex");
    qmlRegisterType<MapBrush>("crowbar.experiments.qml", 1, 0, "Brush");

    I also have helper functions like the following, which are given to the QmlListProperty object:

    static void verticesQmlAppendFunction(QQmlListProperty<MapVertex> *property, MapVertex * value) 
    QQmlListProperty<MapVertex> MapBrush::vertices()
      return QQmlListProperty<MapVertex>(this, NULL, &verticesQmlAppendFunction, &verticesQmlCountFunction, &verticesQmlAtFunction, &verticesQmlClearFunction);

    Is there any reason why this property should be showing up as read-only?

  • Moderators

    @x6herbius Not sure. Are MapVertex and MapBrush QObject derived classes ?

  • @p3c0 Yep, they both are.

  • After further investigation, assignment works if the property type is changed from MapVertex to QObject, even though MapVertex definitely derives from QObject (I'm using signals on it). Might the fact that it's namespaced under a model library (I'm utilising "using namespace" in the code above) be causing problems?

    EDIT: Looks like that was the problem. I went through and fully qualified all of my namespaces and it seemed to fix it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.