View Full Version : setRoleNames in Qt 5
yandi
22nd May 2013, 11:00
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
wysota
22nd May 2013, 11:11
Subclass and reimplement roleNames().
adhyani
28th March 2014, 15:34
Can someone give an example or a code snippet which will show how we can port setRoleNames() API in Qt5?
anda_skoa
30th March 2014, 12:42
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,
_
shsdev
1st May 2014, 19:58
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/qabstractitemmodel.html#roleNames
Best,
Sven
QutWizard
29th October 2014, 17:05
How to reimplement roleNames:
QHash<int, QByteArray> ClassName::roleNames() const
{
QHash<int, QByteArray> roles;
roles[ObjectRole] = "object";
return roles;
}
protected:
QHash<int, QByteArray> roleNames() const;
pip010
8th April 2016, 14:53
well I did just that and the method never get called, any idea why?
anda_skoa
8th April 2016, 15:20
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,
_
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.