Using QAbstractModel
-
@Mihaill said in Using QAbstractModel:
But whot me need do? Need reimplement setData ?
You roles must starts with
Qt::UserRole
(cf. https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel-subclass)So change your enumeration to:
enum DeviceRoles { IdRole = Qt::UserRole, NameRole, IsDoneRole }
-
-
Did you also fix emitSignalUpdateModel ?
-
Fix the roles values for example.
-
As I explained and @KroMignon showed you, your enum values were wrong. You hard coded the same values in that method:
@Mihaill said in Using QAbstractModel:
void ModelRegistration::emitSignalUpdateModel() { auto index = this->index(0); emit dataChanged(index, index, QVector<int>{0,1,2}); }
Change them and use your enum values.
-
It is not work, and this too not work ```
void ModelSchedule::emitSignalUpdateModel()
{
for (int q = 0; q < vectorDataRegistration.count(); q ++){
auto index = this->index(q);
QVector <int> roles;
for (int i = Qt::UserRole; i < Qt::UserRole + 3; i++) {
roles.append(i);
}
qDebug()<<"roles"<<roles;
emit dataChanged(index, index, roles);
}
} -
I do not see any setData reimplementation.
Your DeviceRoles contains wrong values. These IDs are already in use by Qt in the Roles enum.@SGaist said in Using QAbstractModel:
I do not see any setData reimplementation.
Your DeviceRoles contains wrong values. These IDs are already in use by Qt in the Roles enum.@KroMignon said in Using QAbstractModel:
@Mihaill said in Using QAbstractModel:
But whot me need do? Need reimplement setData ?
You roles must starts with
Qt::UserRole
(cf. https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel-subclass)So change your enumeration to:
enum DeviceRoles { IdRole = Qt::UserRole, NameRole, IsDoneRole }
This is not important when using a QML View, the views use the role names anyway and do no depend on the default Qt roles such as DisplayRole.
As for @Mihaill , nowhere in your code is your underlying data changed. Where/how do you change it?
-
@SGaist said in Using QAbstractModel:
I do not see any setData reimplementation.
Your DeviceRoles contains wrong values. These IDs are already in use by Qt in the Roles enum.@KroMignon said in Using QAbstractModel:
@Mihaill said in Using QAbstractModel:
But whot me need do? Need reimplement setData ?
You roles must starts with
Qt::UserRole
(cf. https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel-subclass)So change your enumeration to:
enum DeviceRoles { IdRole = Qt::UserRole, NameRole, IsDoneRole }
This is not important when using a QML View, the views use the role names anyway and do no depend on the default Qt roles such as DisplayRole.
As for @Mihaill , nowhere in your code is your underlying data changed. Where/how do you change it?
@GrecKo said in Using QAbstractModel:
This is not important when using a QML View, the views use the role names anyway and do no depend on the default Qt roles such as DisplayRole.
AFAIK, the engine will request the role names which shall be associated with integer values so that when requesting them, the model does know what to return. Thus these values are still important to properly set otherwise your model will start serving wrong information to the view.
-
@SGaist said in Using QAbstractModel:
I do not see any setData reimplementation.
Your DeviceRoles contains wrong values. These IDs are already in use by Qt in the Roles enum.@KroMignon said in Using QAbstractModel:
@Mihaill said in Using QAbstractModel:
But whot me need do? Need reimplement setData ?
You roles must starts with
Qt::UserRole
(cf. https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel-subclass)So change your enumeration to:
enum DeviceRoles { IdRole = Qt::UserRole, NameRole, IsDoneRole }
This is not important when using a QML View, the views use the role names anyway and do no depend on the default Qt roles such as DisplayRole.
As for @Mihaill , nowhere in your code is your underlying data changed. Where/how do you change it?