Accessing QMap items in QML
Unsolved
QML and Qt Quick
-
Hi all,
I have a number of settings stored by a QMap( name, value).class MachineSettings : public QAbstractListModel { Q_OBJECT public: MachineSettings(); void insert(QString &key, QString &value); Q_INVOKABLE QString get(QString key){ return _settings[key]; }; int rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); qDebug() << "[rowCount] return: " << _settings.count(); return _settings.count(); }; QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { qDebug() << "[data] " << index.row() << " - " << role; return QVariant("**"); }; private: QMap<QString, QString> _settings; };
I passed the variable to QML and used as a ListView model.
How can I access to the QMap's items?ListView { id: listView anchors.left: parent.left ... interactive: false model: mysettings delegate: Item { x: 5 width: 120 height: 40 Row { id: row1 Rectangle { width: 40 height: 40 color: "#ffaaaa" } Text { text: "Key" anchors.verticalCenter: parent.verticalCenter font.bold: true } Text { text: "Val "+model.email anchors.verticalCenter: parent.verticalCenter font.bold: true } spacing: 10 } } }
It generates a list of some rows (how to handle the scroll bar??) containing text 'Key Val undefined'.
The debug output in the rowCount() returns '79' but the qDebugs in data() function does not appair in the console (?).Thanks