Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] ListView model in C++ not getting all elements
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MaxL
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #2

      compare your code with Qt example.

      QTPATH\examples\quick\models\abstractitemmodel

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MaxL
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MaxL
          wrote on last edited by
          #4

          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..

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MaxL
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved