[SOLVED] ListView model in C++ not getting all elements



  • Hi all,

    I'm facing an issue with a listview that has a model built in c++.
    Here is how it works :
    In C++ I have a class, let say MyModel, that subclasses QAbstractListModel. This class has a QList containing C++ Object to display. It also overrides rowCount(...) which returns the number of element in my QList, data(..) that returns the right value according to role and roleNames().
    In my main.cpp I create an object of type MyModel and populate its list of element with 4 objects.
    Once done, I set a context property let say called myModelForQML with this object.

    In QML my listview has its model property set to myModelForQML.
    What happens is that it only displays the first element in my Qlist even though there are 4 of them.
    If I create a model in QML with 4 elements there is no problem, all for of them are displayed correctly.

    If anyone has an hint of what is going wrong, i would really appreciate it.
    Thanks.



  • compare your code with Qt example.

    QTPATH\examples\quick\models\abstractitemmodel



  • Thanks for your answer.
    I did am missing the beginInsertRows when I add an element to the listModel. I will try to add this when I'll get a chance to have a hand on my code.



  • I tried adding beginInsertRows and endInsertRows but it did not change a thing..I don't know what to do because when calling rowCount, the listview does know that it has 4 elements but it only calls data for row 0..



  • I fially found out why it was behaving like that. Objects were deleted so pointer in my QList were invalid as well as my list.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.