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. Triggering common actions for a data model from a view
QtWS25 Last Chance

Triggering common actions for a data model from a view

Scheduled Pinned Locked Moved Unsolved General and Desktop
data modelsviewsqstandarditemmoserialization
9 Posts 4 Posters 2.0k 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.
  • E Offline
    E Offline
    elfring
    wrote on 12 Sept 2018, 09:08 last edited by VRonin 9 Dec 2018, 10:08
    #1

    I have read the documentation for the topic “Model/view programming” several times.
    The data model should support also the following actions at least.

    • Reloading of needed data
    • Storing data in a selected format

    I have got understanding difficulties to trigger such actions directly by a programming interface which is supported by a class like “QTreeView”.

    • May views call member functions from their models directly?
    • Do models need to connect to any signals (or events) for the desired data processing?

    I wonder why it seems to be harder than expected to find existing small Qt examples for this use case.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 12 Sept 2018, 09:24 last edited by
      #2

      Hi, I wrote a library to serialise models in binary, xml, csv and json. You can find it here referred as "Model Serialisation". it's not fully documented (hence the dev branch) but you can find an example usage here

      Don't know if the questions are related to the above but I'll answer

      May views call member functions from their models directly?

      They may and they do

      Do models need to connect to any signals (or events) for the desired data processing?

      A bit to generic of a question. depends on the data processing

      "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 14 Sept 2018, 20:30
      1
      • E Offline
        E Offline
        elfring
        wrote on 12 Sept 2018, 11:35 last edited by
        #3

        May views call member functions from their models directly?
        They may and they do

        Thanks for your quick answer.

        It seems that I have overlooked the useful function “QAbstractItemView::model()”.

        J 1 Reply Last reply 12 Sept 2018, 11:53
        0
        • E elfring
          12 Sept 2018, 11:35

          May views call member functions from their models directly?
          They may and they do

          Thanks for your quick answer.

          It seems that I have overlooked the useful function “QAbstractItemView::model()”.

          J Online
          J Online
          JonB
          wrote on 12 Sept 2018, 11:53 last edited by
          #4

          @elfring
          That function gives the model the view is attached to. From that you can obviously do whatever you fancy on the associated model. Is that what you mean you did not know existed, and so you thought the view could not access the model?

          1 Reply Last reply
          0
          • E Offline
            E Offline
            elfring
            wrote on 12 Sept 2018, 12:32 last edited by
            #5

            Is that what you mean you did not know existed,

            It seems so.

            and so you thought the view could not access the model?

            I needed another moment to recognise this way to get access to the desired model object.

            1 Reply Last reply
            0
            • V VRonin
              12 Sept 2018, 09:24

              Hi, I wrote a library to serialise models in binary, xml, csv and json. You can find it here referred as "Model Serialisation". it's not fully documented (hence the dev branch) but you can find an example usage here

              Don't know if the questions are related to the above but I'll answer

              May views call member functions from their models directly?

              They may and they do

              Do models need to connect to any signals (or events) for the desired data processing?

              A bit to generic of a question. depends on the data processing

              E Offline
              E Offline
              elfring
              wrote on 14 Sept 2018, 20:30 last edited by
              #6

              A bit to generic of a question.

              How do you think about to discuss any more meaningful application examples?

              M 1 Reply Last reply 15 Sept 2018, 17:35
              0
              • E elfring
                14 Sept 2018, 20:30

                A bit to generic of a question.

                How do you think about to discuss any more meaningful application examples?

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 15 Sept 2018, 17:35 last edited by
                #7

                @elfring
                Well to change the internal structure of cppcheck to use models in the
                intended way would be a benefit but to change GUI to QML would not
                in my opinion not bring anything worthwhile besides huge amount of new code to let
                QML access the data. However, it would ensure a very good separation
                between data and presentation as there is no shortcuts
                interfacing QML with c++ backbone models.
                However, cppcheck needs neither animation or hardware accelerated drawing so
                its hard to see what the gain would be. ( compared to the extra work of using QML)

                E 1 Reply Last reply 15 Sept 2018, 17:56
                0
                • M mrjj
                  15 Sept 2018, 17:35

                  @elfring
                  Well to change the internal structure of cppcheck to use models in the
                  intended way would be a benefit but to change GUI to QML would not
                  in my opinion not bring anything worthwhile besides huge amount of new code to let
                  QML access the data. However, it would ensure a very good separation
                  between data and presentation as there is no shortcuts
                  interfacing QML with c++ backbone models.
                  However, cppcheck needs neither animation or hardware accelerated drawing so
                  its hard to see what the gain would be. ( compared to the extra work of using QML)

                  E Offline
                  E Offline
                  elfring
                  wrote on 15 Sept 2018, 17:56 last edited by mrjj
                  #8

                  hi

                  • Will the support change for UI and QML file formats over time?
                    Well QWidgets are very stable and its very unlikely that UI format will radically change.
                    QML is more of a work in progress so it could happen that very old QML file would require some
                    minor changes to load in brand new Qt but given the history of avoiding breaking
                    even binary comparability, its not likely to be a real world issue.

                  • Would you like to help any more with the separation of data structures for models and views?
                    If you mean outside of answering question here in forum, then no thank you. :)

                  E 1 Reply Last reply 17 Sept 2018, 15:52
                  0
                  • E elfring
                    15 Sept 2018, 17:56

                    hi

                    • Will the support change for UI and QML file formats over time?
                      Well QWidgets are very stable and its very unlikely that UI format will radically change.
                      QML is more of a work in progress so it could happen that very old QML file would require some
                      minor changes to load in brand new Qt but given the history of avoiding breaking
                      even binary comparability, its not likely to be a real world issue.

                    • Would you like to help any more with the separation of data structures for models and views?
                      If you mean outside of answering question here in forum, then no thank you. :)

                    E Offline
                    E Offline
                    elfring
                    wrote on 17 Sept 2018, 15:52 last edited by
                    #9

                    If you mean outside of answering question here in forum, then no thank you. :)

                    I am curious then if you would like to clarify related development topics.

                    • Do you know any higher level tools which can display structural differences between standard item models in a clear way?
                    • Have you got any experiences with “diff views” in this software area?
                    1 Reply Last reply
                    0

                    2/9

                    12 Sept 2018, 09:24

                    7 unread
                    • Login

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