Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML invalid property assignment - read-only property
Forum Updated to NodeBB v4.3 + New Features

QML invalid property assignment - read-only property

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    x6herbius
    wrote on 17 Jun 2015, 08:05 last edited by
    #1

    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:

    Brush
    {
      vertices:
      [
        Vertex{},
        Vertex{}
      ]
    }
    

    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) 
    {
      static_cast<MapBrush*>(property->object)->verticesAppend(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?

    P 1 Reply Last reply 17 Jun 2015, 08:46
    0
    • X x6herbius
      17 Jun 2015, 08:05

      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:

      Brush
      {
        vertices:
        [
          Vertex{},
          Vertex{}
        ]
      }
      

      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) 
      {
        static_cast<MapBrush*>(property->object)->verticesAppend(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?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 17 Jun 2015, 08:46 last edited by p3c0
      #2

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

      157

      X 1 Reply Last reply 17 Jun 2015, 15:45
      0
      • P p3c0
        17 Jun 2015, 08:46

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

        X Offline
        X Offline
        x6herbius
        wrote on 17 Jun 2015, 15:45 last edited by
        #3

        @p3c0 Yep, they both are.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          x6herbius
          wrote on 17 Jun 2015, 20:26 last edited by x6herbius
          #4

          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.

          1 Reply Last reply
          0

          1/4

          17 Jun 2015, 08:05

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved