Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.8.0
-
None
-
40206a9f6d7635bb19305d1c8d74908808e3529e
Description
If you query the QSqlQueryModel::rolesNames() it returns a list of seven roles from the base QAbstractItemModel.
In the data function :
QVariant QSqlQueryModel::data(const QModelIndex &item, int role) const { Q_D(const QSqlQueryModel); if (!item.isValid()) return QVariant(); QVariant v; if (role & ~(Qt::DisplayRole | Qt::EditRole)) return v; .... }
It is clear to see it only supports two of those roles: Qt::DisplayRole | Qt::EditRole
In the documentation is states that "The QSqlQueryModel class provides a read-only data model", and so the Qt::EditRole is dubious, if not incorrect.The check should be reduced to check only the Qt::DisplayRole.
If this model's roles were reduced to just the Qt::DisplayRole, as it appears is all they should be stating that they support, then the models would be much easier to use in QML ComboBox's. More fundamentally, the class should state the roles it supports and it doesn't.
Acknowledging the desire not to break code, the roleNames() could be changed to include only Qt::DisplayRole, and allow the edit role until a breaking change can occur, OR it could be seen as an full bug that the Qt::EditRole was even allowed to be used on a read-only model.
Attachments
For Gerrit Dashboard: QTBUG-60857 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
195032,6 | Modify QSqlQueryModel roleNames | dev | qt/qtbase | Status: MERGED | +2 | 0 |