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. QML TableView with custom QAbstractListModel issue
Forum Updated to NodeBB v4.3 + New Features

QML TableView with custom QAbstractListModel issue

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.9k 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.
  • S Offline
    S Offline
    shrao
    wrote on last edited by
    #1

    Hi,

    I have a C++ model extending QAbstractListModel and I have expose this model to QML TableView. The model has got three rows but in the TableView it is displayed as one row. I noticed this as all the three rows were displayed in white color(background) and then the empty rows were displayed with alternating colours. I started debugging this QML by adding a custom row delegate and printed out styleData.row to see if the row index is changing and to my suspicion it is always zero. So I realised that may be something is wrong with my C++ model, replaced my custom model with a dummy list model in QML and it seems to display rows in alternate colours and styleData.row gets incremented in custom row delegate for each row. Anyone has had the same issue or suggest a possible solution/workaround?

    Cheers

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gennon
      wrote on last edited by
      #2

      Hi and welcome,

      It would help a lot if you could post some of your code, like your implementation of the QAbstractListModel. I usually run into these kinds of problems, and it is often just a silly mistake. Another pair of eyes usually does the trick in locating the bug.

      /Gen

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shrao
        wrote on last edited by
        #3

        I figured out what the problem was - My ListModel did not directly derive from QAbstractListModel. It derived from a base class that handled display roles for common attributes of a base model. In my TableView I was not using the base roles as they were not required but for some reason TableView expects the number of roles in the list model to match the columns. As a workaround I cleared the roles in my derived class constructor and removed call to BaseListModelClass::getRoleData() from derived class getRoleData and this fixed the problem. Hope this helps for other users.

        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