Hi Guys,
I try to follow example in forum/internet to using QSqlQueryModel or QSqlTableModel in Qml.
but in doc that setRoleNames is deprecated, how to set new role in Qt 5?
rgds
Hi Guys,
I try to follow example in forum/internet to using QSqlQueryModel or QSqlTableModel in Qml.
but in doc that setRoleNames is deprecated, how to set new role in Qt 5?
rgds
Can someone give an example or a code snippet which will show how we can port setRoleNames() API in Qt5?
See comment #2.
Create a sub class of the model.
Reimplement (overwrite) the roleNames() method.
Neither creating a subclass nor overwriting a virtual method is specific to Qt but basic C++ idioms.
Cheers,
_
Hi,
Well, I had exaclty the same question as yandi. And I did not find the roleNames() method.
Post edited, because I though the roleNames() method wouldn't be a member of QSqlQueryModel, but it is indeed via the QAbstractItemModel:
http://qt-project.org/doc/qt-5/qabst...html#roleNames
Best,
Sven
Last edited by shsdev; 1st May 2014 at 20:10. Reason: My comment was mistaken, corrected
How to reimplement roleNames:
Qt Code:
QHash<int, QByteArray> ClassName::roleNames() const { QHash<int, QByteArray> roles; roles[ObjectRole] = "object"; return roles; } protected: QHash<int, QByteArray> roleNames() const;To copy to clipboard, switch view to plain text mode
well I did just that and the method never get called, any idea why?
Make sure you have the correct signature.
If you are using a C++11 capable compiler, try adding the override keyword so you'll get an error on signature mismatch.
Cheers,
_
Bookmarks