Important: Please read the Qt Code of Conduct -

QSortFilterProxyModel not requesting data...

  • 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;
        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? :(

  • Lifetime Qt Champion


    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;

  • 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

  • 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 :]

  • Lifetime Qt Champion

    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 :)