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. QSortFilterProxyModel not requesting data...
Qt 6.11 is out! See what's new in the release blog

QSortFilterProxyModel not requesting data...

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qsortfilterproxmodelqt quick
5 Posts 2 Posters 3.5k Views 2 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.
  • David.GD Offline
    David.GD Offline
    David.G
    wrote on last edited by
    #1

    I've been trying to integrate a proxy model to my application, but for some weird reason while it reads rows and columns it cannot display the data. My model is a custom one, mostly for general purposes.

    Screenshot with model

    Screenshot with proxy

    void mainController::changeCurrentEntryModel(GenericModel *model)
    {
        auto *proxy = new QSortFilterProxyModel;
        proxy->setSourceModel(model);
    
    
        QMetaObject::invokeMethod(qml_ContentPane,"setCurrentEntriesModel",Q_ARG(QVariant, QVariant::fromValue(proxy)));
    
    }
    

    So, before adding the variable "proxy' I just had it directly to model in QVariant::fromValue and it just works, the data displays and all. But when I put a proxy behind it, it display the correct amount of empty rows... just that.

    So I was wondering if the sort filter model is communicating with the model through debugging and a few qDebugs polling indexes and there's nothing, nada. No request being made from the proxy model.

    I'm stuck, I'm not sure what is holding the proxy back since it's not making any requests. I followed the examples provided in Qt Creator (examples section) and read this article about it (since I use QML/QtQuick as my visual front). Only thing I saw was that with QStandardItemModel it apparently works.

    As I said before, ListViews, TreeViews,TableViews works fine with my model implementation (directly) but when it comes to proxy model, no dice.

    Any suggestion? :(

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If I understood you correctly you have something like:

      -> ListView -> Model -> Proxy and you are trying to set an index on the model that comes from the proxy.

      What you need to do is set the proxy between the view and the model so basically:

      auto *proxy = new QSortFilterProxyModel;
      proxy->setSourceModel(model);
      view->setModel(proxy)
      

      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
      0
      • David.GD Offline
        David.GD Offline
        David.G
        wrote on last edited by
        #3

        Hi @SGaist,

        Thanks for replying. Yea, I'm setting the proxy as ListView's model (practically just like your code). After calling setCurrentEntriesModel in my app, the QML side outputs this.

        qrc:/qml/_ContentPane.qml(87): QSortFilterProxyModel(0x2f064f061c0)
        

        So at least on the QML side it's recognized as such. The indexes the ListView get should be purely from the proxy itself. I'm going to subclass QAbstractProxyModel very soon (probably after this comment). I did it yesterday to no avail honestly, this blocker issue is really playing me, could be either something really silly to an ugly gotcha moment.

        However... when I subclassed QAbstractProxyModel the first time it made no attempt to rely data or ask for index or parent... (at least in the classes I overrode)

        Oh well, guesswork won't do much. Time to keep digging I guess

        1 Reply Last reply
        0
        • David.GD Offline
          David.GD Offline
          David.G
          wrote on last edited by
          #4

          I ended up ditching the custom model and moved everything to QStandardItemModel, thanks to being exposed to Qt for months the transition went pretty smoothly (mostly due to not changing class name).

          So, I think most of the situation boils down to index mapping. The structure of my custom model probably had to do a lot with it. After reading Qt Commercial Support Weekly #10: Sorting, filtering and advanced manipulation with proxy models which I recommend reading if you(anyone reading) wants to go on a journey implementing proxy models. Sadly, I'm already behind schedule so favoring QStandardItemModel didn't take long, but if I went ahead to nail down the index mapping it might have taken me more than it's worth.

          bottomline, proxy works as expected. Hurrah :]

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Good !

            Since you have it working now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know a solution has been found :)

            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
            0

            • Login

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