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. Support for QStandardItem proxies?
Forum Update on Monday, May 27th 2025

Support for QStandardItem proxies?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstandarditemcustom datadata modelsproxyadapter
27 Posts 3 Posters 8.1k 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.
  • VRoninV VRonin

    Good spot, I'm surprised it didn't just assert. I got shouted at in code review for having models that didn't assert when index.model()!=this

    @elfring replace auto x(sourceModel()->data(index)); with auto x=QIdentityProxyModel::data(index, role);

    E Offline
    E Offline
    elfring
    wrote on last edited by
    #16

    replace auto x(sourceModel()->data(index)); with auto x=QIdentityProxyModel::data(index, role);

    Thanks for this suggestion.

    • Unfortunately, I selected a questionable member function call combination before.
    • The test case is working as expected together with the statement “return mm.text;” now.
    1 Reply Last reply
    0
    • VRoninV VRonin

      Good spot, I'm surprised it didn't just assert. I got shouted at in code review for having models that didn't assert when index.model()!=this

      @elfring replace auto x(sourceModel()->data(index)); with auto x=QIdentityProxyModel::data(index, role);

      E Offline
      E Offline
      elfring
      wrote on last edited by
      #17

      Good spot, I'm surprised it didn't just assert.

      • Did I try the usage of model indexes out in appropriate way for my test case?
      • Do indexes need to be different for proxy and source models?
      VRoninV 1 Reply Last reply
      0
      • E elfring

        Good spot, I'm surprised it didn't just assert.

        • Did I try the usage of model indexes out in appropriate way for my test case?
        • Do indexes need to be different for proxy and source models?
        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #18

        @elfring said in Support for QStandardItem proxies?:

        Did I try the usage of model indexes out in appropriate way for my test case?

        Usually you'd want a Q_ASSERT that uses checkIndex()

        Do indexes need to be different for proxy and source models?

        Yes, obviously

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        E 1 Reply Last reply
        0
        • VRoninV VRonin

          @elfring said in Support for QStandardItem proxies?:

          Did I try the usage of model indexes out in appropriate way for my test case?

          Usually you'd want a Q_ASSERT that uses checkIndex()

          Do indexes need to be different for proxy and source models?

          Yes, obviously

          E Offline
          E Offline
          elfring
          wrote on last edited by
          #19

          Yes, obviously

          • Should the difference between indexes for proxy and source models be better described in the Qt documentation?
          • How do you think about the introduction of a class like QProxyModelIndex then?
          VRoninV 1 Reply Last reply
          0
          • E elfring

            Yes, obviously

            • Should the difference between indexes for proxy and source models be better described in the Qt documentation?
            • How do you think about the introduction of a class like QProxyModelIndex then?
            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #20

            @elfring said in Support for QStandardItem proxies?:

            How do you think about the introduction of a class like QProxyModelIndex then?

            QAbstractPorxyModel::mapToSource/QAbstractPorxyModel::mapFromSource already do everything that class would do so I see no gain in introducing it

            Should the difference between indexes for proxy and source models be better described in the Qt documentation?

            A proxy model is still a model, the docs say "Note that it's undefined behavior to pass illegal indices to item models" so I feel it is documented already

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            E 1 Reply Last reply
            1
            • VRoninV VRonin

              @elfring said in Support for QStandardItem proxies?:

              How do you think about the introduction of a class like QProxyModelIndex then?

              QAbstractPorxyModel::mapToSource/QAbstractPorxyModel::mapFromSource already do everything that class would do so I see no gain in introducing it

              Should the difference between indexes for proxy and source models be better described in the Qt documentation?

              A proxy model is still a model, the docs say "Note that it's undefined behavior to pass illegal indices to item models" so I feel it is documented already

              E Offline
              E Offline
              elfring
              wrote on last edited by
              #21

              A proxy model is still a model,

              This information is generally appropriate.

              the docs say "Note that it's undefined behavior to pass illegal indices to item models"

              A constraint is mentioned.

              so I feel it is documented already

              Now I imagine that a better class design can prevent the passing of inappropriate indexes a bit more.
              How are the chances to specify that QAbstractProxyModel-like objects need to work with QProxyModelIndex objects instead?

              VRoninV 1 Reply Last reply
              0
              • E elfring

                A proxy model is still a model,

                This information is generally appropriate.

                the docs say "Note that it's undefined behavior to pass illegal indices to item models"

                A constraint is mentioned.

                so I feel it is documented already

                Now I imagine that a better class design can prevent the passing of inappropriate indexes a bit more.
                How are the chances to specify that QAbstractProxyModel-like objects need to work with QProxyModelIndex objects instead?

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #22

                @elfring said in Support for QStandardItem proxies?:

                Now I imagine that a better class design can prevent the passing of inappropriate indexes a bit more.

                Agree that's why I said:

                I'm surprised it didn't just assert.

                How are the chances to specify that QAbstractProxyModel-like objects need to work with QProxyModelIndex objects instead?

                1. QAbstractProxyModel is a subclass of QAbstractItemModel and the view should not care whether the model it's attached to is a proxy or not

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                E 1 Reply Last reply
                2
                • VRoninV VRonin

                  @elfring said in Support for QStandardItem proxies?:

                  Now I imagine that a better class design can prevent the passing of inappropriate indexes a bit more.

                  Agree that's why I said:

                  I'm surprised it didn't just assert.

                  How are the chances to specify that QAbstractProxyModel-like objects need to work with QProxyModelIndex objects instead?

                  1. QAbstractProxyModel is a subclass of QAbstractItemModel and the view should not care whether the model it's attached to is a proxy or not
                  E Offline
                  E Offline
                  elfring
                  wrote on last edited by
                  #23

                  the view should not care whether the model it's attached to is a proxy or not

                  Can overloaded functions (from a specific proxy class) help any more to detect questionable indexes?

                  VRoninV 1 Reply Last reply
                  0
                  • E elfring

                    the view should not care whether the model it's attached to is a proxy or not

                    Can overloaded functions (from a specific proxy class) help any more to detect questionable indexes?

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #24

                    @elfring said in Support for QStandardItem proxies?:

                    Can overloaded functions (from a specific proxy class) help any more to detect questionable indexes?

                    It can help but there's no bullet proof solution.

                    In the meantime I submitted a change to QStandardItemModel that would have made your bug assert in debug

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    E Christian EhrlicherC 2 Replies Last reply
                    1
                    • VRoninV VRonin

                      @elfring said in Support for QStandardItem proxies?:

                      Can overloaded functions (from a specific proxy class) help any more to detect questionable indexes?

                      It can help but there's no bullet proof solution.

                      In the meantime I submitted a change to QStandardItemModel that would have made your bug assert in debug

                      E Offline
                      E Offline
                      elfring
                      wrote on last edited by
                      #25

                      In the meantime I submitted a change to QStandardItemModel that would have made your bug assert in debug

                      I find it interesting that my clarification request triggered such a software evolution finally.
                      Would you like to continue the development discussion also around proxies for QStandardItem (or eventually other classes)?

                      1 Reply Last reply
                      0
                      • VRoninV VRonin

                        @elfring said in Support for QStandardItem proxies?:

                        Can overloaded functions (from a specific proxy class) help any more to detect questionable indexes?

                        It can help but there's no bullet proof solution.

                        In the meantime I submitted a change to QStandardItemModel that would have made your bug assert in debug

                        Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #26

                        @VRonin said in Support for QStandardItem proxies?:

                        assert in debug

                        But only when Qt was compiled in debug mode which is for sure not the case...

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        VRoninV 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @VRonin said in Support for QStandardItem proxies?:

                          assert in debug

                          But only when Qt was compiled in debug mode which is for sure not the case...

                          VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by
                          #27

                          @Christian-Ehrlicher said in Support for QStandardItem proxies?:

                          But only when Qt was compiled in debug mode

                          Yes, as the docs say using invalid indexes remains undefined behaviour, I am just trying to help users spot these cases

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          1 Reply Last reply
                          1

                          • Login

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