In the following you'll find my custom model. I reduced it to the just necessary things:
class myClass : public QAbstractListModel
{
Q_OBJECT
enum Role {
id=Qt::UserRole,
call,
name,
date,
time,
};
public:
...
private:
QList<QJsonObject> database;
...
};
...
void myClass::onMQTT(...)
{
...
QJsonObject jsonObject = jsonResponse.object();
if(database.size() == 8) {
beginRemoveRows(QModelIndex(), 0, 0);
database.pop_front();
endRemoveRows();
}
beginInsertRows(QModelIndex(), database.size(), database.size());
database.push_back(jsonObject);
endInsertRows();
}
...
For displaying I use a QML ListView. The displaying works fine. Every time I receive a packet over the network, the onMQTT callback is called and something new is added to the database and it's also displayed in the ListView.
When there are 8 elements in the list, the oldest element shall be deleted and a new element should be added. However, the removing of the rows is not performed. In fact the 8 oldest elements stay visible and nothing new is added. I just see the first incoming 8 messages and that's it. Its not updated at all, although the data in the database is exchanged correctly.