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. Modifying data outside a Model and View
Forum Updated to NodeBB v4.3 + New Features

Modifying data outside a Model and View

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 603 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.
  • E Offline
    E Offline
    EaccB
    wrote on 28 Jun 2020, 13:28 last edited by
    #1

    I have a custom Model class which contains a pointer to a vector held elsewhere, and a View associated with the Model.

    Is it acceptable to modify (add, edit, delete, etc) the vector directly? I.e, not through the model or the view. If so, how would I notify the model that the data has been changed, or does it update automatically?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Jun 2020, 16:22 last edited by
      #2

      Hi,

      Your model can't know of any changes to your vector unless you give an API to that vector that allows to get the information.

      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
      1
      • E Offline
        E Offline
        EaccB
        wrote on 28 Jun 2020, 16:26 last edited by EaccB
        #3

        Would it be best to have all data changes (which affect the view) handled from within the model? What's the best practise with this sort of thing? If I do a sort on the model, will it also sort the vector?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 28 Jun 2020, 16:50 last edited by
          #4

          See the documentation.
          When the complete data changed (whyever this should happen) you can use layoutChanged() but it should be avoided. Use dataChanged() wherever possible.
          Sorting has nothing to do with the QAbstractItemModel so no your data will not change.

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

          E 1 Reply Last reply 28 Jun 2020, 17:01
          2
          • C Christian Ehrlicher
            28 Jun 2020, 16:50

            See the documentation.
            When the complete data changed (whyever this should happen) you can use layoutChanged() but it should be avoided. Use dataChanged() wherever possible.
            Sorting has nothing to do with the QAbstractItemModel so no your data will not change.

            E Offline
            E Offline
            EaccB
            wrote on 28 Jun 2020, 17:01 last edited by
            #5

            @Christian-Ehrlicher said in Modifying data outside a Model and View:

            Sorting has nothing to do with the QAbstractItemModel so no your data will not change.

            The documentation suggests that I can reimplement QAbstractItemModel::sort() to sort the data.

            I need both the vector and the model sorted.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 28 Jun 2020, 17:42 last edited by
              #6

              Why do you need to sort your data when you can simply use a QSortFilterProxyModel?

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

              E 1 Reply Last reply 28 Jun 2020, 19:24
              1
              • C Christian Ehrlicher
                28 Jun 2020, 17:42

                Why do you need to sort your data when you can simply use a QSortFilterProxyModel?

                E Offline
                E Offline
                EaccB
                wrote on 28 Jun 2020, 19:24 last edited by
                #7

                @Christian-Ehrlicher

                If I use QSortFilterProxyModel, will it sort the vector too?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 28 Jun 2020, 19:26 last edited by
                  #8

                  No, it acts on top of the model it proxies.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  E 1 Reply Last reply 29 Jun 2020, 09:26
                  1
                  • S SGaist
                    28 Jun 2020, 19:26

                    No, it acts on top of the model it proxies.

                    E Offline
                    E Offline
                    EaccB
                    wrote on 29 Jun 2020, 09:26 last edited by
                    #9

                    @SGaist

                    So I would have to sort the vector manually then?

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 29 Jun 2020, 09:54 last edited by
                      #10

                      @EaccB said in Modifying data outside a Model and View:

                      So I would have to sort the vector manually then?

                      Again: use a QSortFilterProxyModel when you want to display the data sorted.

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

                      1 Reply Last reply
                      0

                      10/10

                      29 Jun 2020, 09:54

                      • Login

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