Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] QQmlListProperty: QObject subclass usage
QtWS25 Last Chance

[SOLVED] QQmlListProperty: QObject subclass usage

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 3.8k Views
  • 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.
  • R Offline
    R Offline
    RaubTieR
    wrote on last edited by
    #1

    I have a QObject subclass like in "this":http://qt-project.org/doc/qt-5.0/qtquick/qml-referenceexamples-properties.html example, and I have a list property in it:
    @class Subclass: public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QQmlListProperty<Subclass> content READ content)
    QList<Subclass*> mContent;
    public:
    QQmlListProperty<Subclass> content() {return QQmlListProperty<Subclass>(this, mContent);}
    }@

    I don't see any difference, however if I try to set it from QML, I get "Cannot assign multiple values to a singular property". BUT! With the following code everything works:
    @class Subclass: public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QQmlListProperty<QObject> content READ content)
    QList<QObject*> mContent;
    public:
    QQmlListProperty<QObject> content() {return QQmlListProperty<QObject>(this, mContent);}
    }@

    Can you tell me what is wrong? I do want QQmlListProperty<Subclass> to have an automatic typecheck, because I need that only Subclass and it's children to be set as "content".

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Hi,

      Do you register "Subclass" with the QML type system via qmlRegisterType()?

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RaubTieR
        wrote on last edited by
        #3

        OMG!
        Well, that solved the whole thing :) I were using Sub-Subclasses from QML and those were registered, while Subclass itself wasn't.
        Thank you very much!

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jbarbosa
          wrote on last edited by
          #4

          damm, had the same problem.

          for the record, the error message was

          Invalid property assignment: "roles" is a read-only property

          where
          Q_PROPERTY(QQmlListProperty<ModelRole> roles READ roleObjects)

          1 Reply Last reply
          0

          • Login

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