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. Accessing QSortFilterProxyModel from QML
Forum Updated to NodeBB v4.3 + New Features

Accessing QSortFilterProxyModel from QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 657 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by
    #1

    I have a Model created in C++, register in main as a singleton, and succesfully in use in a view in QML:

    qmlRegisterSingletonType<GatewayModel>(
                 "GatewayModel", 1, 0, "GatewayModelQML",
                 [](QQmlEngine *eng, QJSEngine *js) -> QObject *
     {
         Q_UNUSED(js);
         eng->setObjectOwnership(GatewayModel::instance(),
                                 QQmlEngine::ObjectOwnership::CppOwnership);
         return GatewayModel::instance();
     });
    

    I now want my QML code to use a QSortFilterProxyModel sitting in front of my "GatewayModel". How do I insert the proxy inbetween my QML code and my model? (In C++? In QML?? How)

    eyllanescE 1 Reply Last reply
    0
    • ocgltdO ocgltd

      I have a Model created in C++, register in main as a singleton, and succesfully in use in a view in QML:

      qmlRegisterSingletonType<GatewayModel>(
                   "GatewayModel", 1, 0, "GatewayModelQML",
                   [](QQmlEngine *eng, QJSEngine *js) -> QObject *
       {
           Q_UNUSED(js);
           eng->setObjectOwnership(GatewayModel::instance(),
                                   QQmlEngine::ObjectOwnership::CppOwnership);
           return GatewayModel::instance();
       });
      

      I now want my QML code to use a QSortFilterProxyModel sitting in front of my "GatewayModel". How do I insert the proxy inbetween my QML code and my model? (In C++? In QML?? How)

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @ocgltd I need more context to help you but I think that if you want to filter or sort in QML then it is preferable to use this project: https://github.com/oKcerG/SortFilterProxyModel

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      ocgltdO 1 Reply Last reply
      0
      • eyllanescE eyllanesc

        @ocgltd I need more context to help you but I think that if you want to filter or sort in QML then it is preferable to use this project: https://github.com/oKcerG/SortFilterProxyModel

        ocgltdO Offline
        ocgltdO Offline
        ocgltd
        wrote on last edited by ocgltd
        #3

        @eyllanesc I"m not sure why that project is preferred, the QSortFilterProxyModel seems pretty straight forward. I'm just not sure how to instantiate it so it sits between my GatewayModel singleton and QML.

        1 Reply Last reply
        0
        • Marko StankeM Offline
          Marko StankeM Offline
          Marko Stanke
          wrote on last edited by
          #4

          I think what you want is to set the source model.

          proxyModel.setSourceModel(*instance of GatewayModel*);
          

          And then just declare it in main:

          engine.rootContext()->setContextProperty("ProxyModel",  instance of ProxyModel);
          
          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