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. How do a correct MVC Pattern in Qt?
Forum Updated to NodeBB v4.3 + New Features

How do a correct MVC Pattern in Qt?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.6k 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.
  • M Offline
    M Offline
    MisteKiste
    wrote on last edited by
    #1

    Hello,
    I think I build a bad architecture in my application. I just implement the MVC pattern wrong I think. Here is my (probably wrong) solution:

    I have a view that have access to the model which is hold in my "controler".When the user do changes on view the view edit the data in model. For example when the user wants to save the data, he can click on a save
    button and the button calls a function saveData() from the contoler. The controler just use the model and call functions to update the data in database.

    I hope you understand the szenario and sorry for my bad english. What do you think about it? How can i do it better? Whats the disadvantage of my architecture?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MisteKiste
      wrote on last edited by
      #2

      Mhm can nobody help me? Or did I explain my problem too bad?

      1 Reply Last reply
      0
      • jerome_isAviableJ Offline
        jerome_isAviableJ Offline
        jerome_isAviable
        wrote on last edited by
        #3

        the idea of the model is to construct an access interface to datas.
        So... you need to put it inside a variable if you need to change/interact with some other event, OR reconstruct it each time.
        The way i do, for exemple for link two TreeView together (when i click on a line of the first treeview, the other one show me the linked datas...) is to memorize each model datas of my second treeview inside a QHash, and then, use "my_model_second_view->setModel(my_hash[id])" for show the correct model.

        Also, there what is a contrller is name in Qt: a delegate.

        there is some good explain aorund this on youtube (try to search at "deep dive model/view", it is a little bit long, and 6 parts, but really good explain for use it).

        hope this help.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hpollak
          wrote on last edited by
          #4

          There is a good article about it in the documentation (4.8).

          "see model-view-programming":http://qt-project.org/doc/qt-4.8/model-view-programming.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            MVC is much broader than the item views implemented in Qt. And the items views implemented in Qt don't really follow MVC: there is no controller class involved, but a delegate is introduced.

            So, a general question about MVC architecture (which indeed, is too vague for me to get into) cannot be answered with a reference to how Qt implements item views.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MisteKiste
              wrote on last edited by
              #6

              But whats the reason why Qt didn't implement the common MVC pattern?
              Now I didn't use the model-view concept from Qt. Do you think the architecture I described in main post is okay? My goal was to capsule the view and logik.

              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