Convert Qt4.8 to Qt5.3 Project - QAbstractItemModel
Unsolved
Mobile and Embedded
-
Hi,
I'm using sqlite database and generate some table models for qml. This is working fine with qt4.8.
No i have converted the qt4 project to qt5.3 and thevoid setRoleNames(const QHash<int, QByteArray> & roleNames)
is not longer available.
How is the best way to use new "roleNames()" function?
// current qt4.8 void database_model::generate_role_names() { QHash<int, QByteArray> role_names; for(int i = 0; i < record().count(); ++i) { role_names[Qt::UserRole + i + 1] = record().fieldName(i).toLatin1(); // obsolete Qt5 .toAscii() } setRoleNames(role_names); // obsolete Qt5 }
Any ideas?
Thank you
-
Hi,
i tried this and it seems to work correct...
QHash<int, QByteArray> database_model::roleNames() const { QHash<int, QByteArray> role_names; for(int i = 0; i < record().count(); ++i) { role_names[Qt::UserRole + i + 1] = record().fieldName(i).toLatin1(); } return role_names; }
protected: QHash<int, QByteArray> roleNames() const;
Any ideas or comments or any better solution?
Thanks
Ferdl -
Hi,
AFAIK, that's the correct way to do it.