title: How to access list property of C++ object in QML
body: <p>I have started to learn the Qt 5 and got stuck at one point for a long time.</p>
  
  <p>I have two classes. ScoreHandler handles a list of ScoreRecords. I create those two classes in C++ and set an instance of ScoreHandler as a context property. Now in QML I can assign the model, but the delegate can not see properties of ScoreRecord. Do I have to register something somewhere? Please help me.</p>
  
  <p>scorerecord.h</p>
  
  <pre><code>class ScoreRecord : public QObject
  {
      Q_OBJECT
  
      Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
      Q_PROPERTY(QString date READ date WRITE setDate NOTIFY dateChanged)
      Q_PROPERTY(QString score READ score WRITE setScore NOTIFY scoreChanged)
  public:
      ScoreRecord(QObject *parent = 0);
      ScoreRecord(const QString&amp; n, const QString &amp;d, const QString &amp;s, QObject *parent = 0);
      QString name() const;
      void setName(const QString &amp;str);
      QString date() const;
      void setDate(const QString &amp;str);
      QString score() const;
      void setScore(const QString &amp;str);
  
  
  signals:
      void nameChanged();
      void dateChanged();
      void scoreChanged();
  
  public slots:
  
  private:
      QString m_name;
      QString m_date;
      QString m_score;
  };
  </code></pre>
  
  <p>scorehandler.h</p>
  
  <pre><code>class ScoreHandler : public QObject
  {
      Q_OBJECT
  private:
      const char* SCORE_TABLE_FILENAME;
  
      struct scoreRow {
          char name[128];
          char date[32];
          char score[16];
      };
  
  
  public:
      explicit ScoreHandler(QObject *parent = 0);
      QList&lt;ScoreRecord *&gt; scoreList;
  
  signals:
  
  public slots:
      void SaveScore(const QString &amp;name, const QString &amp;date, const QString &amp;score);
      void LoadScore();
  };
  </code></pre>
  
  <p>main.c</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  
      QGuiApplication app(argc, argv);
      QtQuick2ApplicationViewer viewer;
  
      ScoreHandler* scoreHandler = new ScoreHandler();
      QQmlContext* ctx = viewer.rootContext();
      ctx-&gt;setContextProperty("MyScoreModel", QVariant::fromValue(scoreHandler-&gt;scoreList));
      viewer.setMainQmlFile(QStringLiteral("qml/qmlListView/main.qml"));
  
      viewer.showExpanded();
  
      return app.exec();
  }
  </code></pre>
  
  <p>QML file</p>
  
  <pre><code>import QtQuick 2.0
  
  Rectangle {
      width: 360
      height: 360
  
      ListView {
          width: 100; height: 100
          anchors.fill: parent
  
          model: MyScoreModel
          delegate: Text {
              text: name
          }
      }
  }
  </code></pre>
  
  <p>And please can somebody explain me, why the following code works? What is the reason?</p>
  
  <p>main.c</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  
      QGuiApplication app(argc, argv);
      QtQuick2ApplicationViewer viewer;
  
      ScoreHandler* scoreHandler = new ScoreHandler();
      QList&lt;QObject *&gt; scoreList;
  
      scoreList.append(new ScoreRecord("Jmeno1", "datum1", "score1"));
      scoreList.append(new ScoreRecord("Jmeno2", "datum2", "score2"));
      scoreList.append(new ScoreRecord("Jmeno3", "datum3", "score3"));
  
      QQmlContext* ctx = viewer.rootContext();
      ctx-&gt;setContextProperty("MyScoreModel", QVariant::fromValue(scoreList));
      viewer.setMainQmlFile(QStringLiteral("qml/qmlListView/main.qml"));
  
      viewer.showExpanded();
  
      return app.exec();
  }
  </code></pre>