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] qobjectlist-based model explanation
Qt 6.11 is out! See what's new in the release blog

[solved] qobjectlist-based model explanation

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 2.8k Views 1 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.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    @
    class DataObject : public QObject
    {
    Q_OBJECT

     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
     Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
     ...
    

    };

    int main(int argc, char ** argv)
    {
    QApplication app(argc, argv);

     QList<QObject*> dataList;
     dataList.append(new DataObject("Item 1", "red"));
     dataList.append(new DataObject("Item 2", "green"));
     dataList.append(new DataObject("Item 3", "blue"));
     dataList.append(new DataObject("Item 4", "yellow"));
    
     QDeclarativeView view;
     QDeclarativeContext *ctxt = view.rootContext();
     ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
     ...
    

    @

    if i wrote this so:
    @
    Q_PROPERTY(QString name READ *get_*name WRITE setName NOTIFY nameChanged)
    @
    what should i write to obtain the same result?

    now here:
    @
    class DataObject : public QObject
    {
    Q_OBJECT

     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
     Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
     ...
    

    };
    @
    should i write a DataObject.cpp with the constructor? do you declare an explicit constructor in the header file DataObject.h? how do you write the constructor in this case?
    must i declare QString name and QString color as variables in the header file DataObject.h?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      spode
      wrote on last edited by
      #2

      solution: i MUST write the constructor; yes, i must declare an explicit constructor of the class, to inizializate variabols and so on; yes, i must declarare all the variables i have used in Q_PROPERTYs in the header.

      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