Add new item in ListView through С++ code
-
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!