Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractListModel returning undefined when cleared and repopulated

QAbstractListModel returning undefined when cleared and repopulated

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 585 Views
  • 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.
  • J Offline
    J Offline
    Jpraccio
    wrote on last edited by
    #1

    I have a class derived from QAbstractListModel that is connected to a ListView. When another ListView changes, I need to change the contents of the Model. I can successfully make the alterations to the model and update the ListView. However, I get an undefined being returned at some point in the update. Don't know that it's a big deal since everything works. But it tweeks me. I want to confirm it's what I think. The clearing of the model returns an empty list before the next updates. Is there a better way to set this up? There seems to be no way to clear a ListView and repopulate it easily, that I've found.

        beginRemoveRows(this->index(_currentList.size()), 0, _currentList.size());
        _currentList.clear();
        endRemoveRows();
    
        beginInsertRows(this->index(0), 0, _durationList[ts->string()].size());
        _currentList = _durationList[ts->string()];
        endInsertRows();
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Since you are nuking the whole content and adding new stuff, the beginResetModel/endResetModel pair would likely make more sense here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J Offline
        J Offline
        Jpraccio
        wrote on last edited by
        #3

        Great, thanks. Missed that in the docs.

        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