You can add an Q_INVOKABLE function to the QAbstractItemModel derived class like this:
...
Q_INVOKABLE QVariantMap get(int row);
...
QVariantMap get(int row) {
QHash<int,QByteArray> names = roleNames();
QHashIterator<int, QByteArray> i(names);
QVariantMap res;
while (i.hasNext()) {
i.next();
QModelIndex idx = index(row, 0);
QVariant data = idx.data(i.key());
res[i.value()] = data;
//cout << i.key() << ": " << i.value() << endl;
}
return res;
}
This will return something like { "bookTitle" : QVariant("Bible"), "year" : QVariant(-2000) }
so you could use .bookTitle on it
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…