Important: Please read the Qt Code of Conduct -

Depends on non-NOTIFYable properties

  • I have implemented c++ class

    class GameList : public QAbstractListModel
        GameList(QObject *parent = nullptr);
        int rowCount(const QModelIndex &parent = QModelIndex()) const override;
        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
        void fillGameList() noexcept;
        QList<QString> m_gameList;
    int GameList::rowCount(const QModelIndex &parent) const
            return 0;
        return m_gameList.size();
    QVariant GameList::data(const QModelIndex &index, int role) const
        if (!index.isValid())
            return QVariant();
        if (index.row() >= m_gameList.size() || index.row() < 0)
            return QVariant();
        if(role == Qt::DisplayRole)
        return QVariant();

    and QML like that:

    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Row {
                model: gameList
                Text{ text: data + "  " }

    I expect that I get data items (there are QString type) but on the form I have [object QObject] [object QObject] ....
    and error: QQmlExpression: Expression qrc:/main.qml:13:25 depends on non-NOTIFYable properties:

    What is wrong with this code?

    Thanks in advance

  • @milosz Hi,

    data is a property available from type Item in QML. You need to use display keyword to access "data" from the model.

    Text{ text: display }

    This is documented here QAbstractItemModel::roleNames()

    Alternatively you can provide your own role names by overriding QAbstractItemModel::roleNames()

  • It works - thanks a lot Gojir4

Log in to reply