Qt 6.12 LTS is out! See what's new in the release
blog
Add new item in ListView through С++ code
QML and Qt Quick
4
Posts
3
Posters
3.2k
Views
1
Watching
-
A couple of things:
- You should probably derive your DataList class from QAbstractListModel rather than QObject - it's made to do what you want here
- When adding items to your DataList, make sure to call beginInsertRows before and endInsertRows after.
-
I used this in my code:
bool ImageModel::addImage(QString id, QString description, int duration_secs) { beginInsertRows(QModelIndex(), m_imageList.count(), m_imageList.count()); StructImage struct_image; m_imageList << struct_image; endInsertRows(); return true; }hope it helps!