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. Question about model/view design
Qt 6.11 is out! See what's new in the release blog

Question about model/view design

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k 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.
  • J Offline
    J Offline
    joshhighley
    wrote on last edited by
    #1

    I'm having trouble getting my functionality to fit with Qt's model/view architecture. Instead of explaining my exact situation, it's easier to do an analogy:

    The analogous app has a folder list on the left, and a list of files on the right (in a table). The user can select multiple folders in the list on the left and I need to show all the selected folders' files in a single sorted table on the right.

    My model extends QAbstractItemModel and has a list of all the folders displayed on the left from which it builds a single list of all the files contained by all the folders. My table view of files extends QTableView and uses the selectionChanged(QItemSelection selected, QItemSelection deselected) method to receive notification of folder selection changes.

    My problem is that I can't figure out how to get a filtered list of files from the model without telling the model which folders are selected, which would break the model/view separation. Qt's model/view classes and methods are still a bit new to me, so I may be missing an obvious solution.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What you are looking for, I think, is the proxy model idea. A proxy model is a QAbstractItemModel that sits between another QAbstractItemModel that supplies data, and a view (or yet another proxy model) on top of that. There are several, but you are looking for [[doc:QSortFilterProxyModel]] I think.

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

        Well, I tried QSortFilterProxyModel and I think it will work for what I need. However, the JRE is now crashing with an "EXCEPTION_ACCESS_VIOLATION" in QtGui4.dll whenever I call the "reset()" or "invalidate()" method in my model after the data has changed. If my model class extends QAbstractItemModel, then I get no error when calling reset(). Also, the "Problematic frame" in QtGui4.dll as reported by the dump is the same whether I call reset() or invalidate(). It seems the issue is in the native code in QSortFilterProxyModel. I've tried 4.5.2 and 4.6.3 on win32. Ugh.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Sorry, I know nothing about java and its possible problems with model-view. Note that a QSortFilterProxyModel does not replace a QAbstractItemModel, but is used on top of it.

          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