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. [Solved] Model/View design question
Forum Updated to NodeBB v4.3 + New Features

[Solved] Model/View design question

Scheduled Pinned Locked Moved General and Desktop
model-view
7 Posts 3 Posters 2.2k Views 3 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by Joel Bodenmann
    #1

    I have a generic question regarding model/view design: When I have a custom subclass of a view class and a custom subclass of a model class, is it okay to make the model become a member of the view and create the model instance inside the constructor of the view class?

    My reasoning to do so is that I can simply use the custom view class as a custom widget which I can use in my application. This way I save creating a custom widget class which has both the custom view and the custom model classes as members.

    Any tips and hints are appreciated.

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    M 1 Reply Last reply
    0
    • Joel BodenmannJ Joel Bodenmann

      I have a generic question regarding model/view design: When I have a custom subclass of a view class and a custom subclass of a model class, is it okay to make the model become a member of the view and create the model instance inside the constructor of the view class?

      My reasoning to do so is that I can simply use the custom view class as a custom widget which I can use in my application. This way I save creating a custom widget class which has both the custom view and the custom model classes as members.

      Any tips and hints are appreciated.

      M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      you can do it but, of course, is less flexible than using external model.

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      Joel BodenmannJ 1 Reply Last reply
      0
      • M mcosta

        Hi,

        you can do it but, of course, is less flexible than using external model.

        Joel BodenmannJ Offline
        Joel BodenmannJ Offline
        Joel Bodenmann
        wrote on last edited by
        #3

        @mcosta Thanks for your answer.
        So the proper way is to create three individual custom classes for the view, the model and the assembled widget?

        Industrial process automation software: https://simulton.com
        Embedded Graphics & GUI library: https://ugfx.io

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There are 2 components actually - the model and the view. The view is a widget already so you can use it directly. There's just a matter of where to keep the model.

          You can either contain instances of both the view and model in some other class like you said or subclass the view and have the model as a member for convenience - similar to what QTreeWidget does with QTreeView and QStandardItemModel.

          Joel BodenmannJ 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            There are 2 components actually - the model and the view. The view is a widget already so you can use it directly. There's just a matter of where to keep the model.

            You can either contain instances of both the view and model in some other class like you said or subclass the view and have the model as a member for convenience - similar to what QTreeWidget does with QTreeView and QStandardItemModel.

            Joel BodenmannJ Offline
            Joel BodenmannJ Offline
            Joel Bodenmann
            wrote on last edited by
            #5

            @Chris-Kawa said:

            You can either contain instances of both the view and model in some other class like you said or subclass the view and have the model as a member for convenience - similar to what QTreeWidget does with QTreeView and QStandardItemModel.

            Which one is the recommended way? What are the benefits of having a separate widget class?

            Industrial process automation software: https://simulton.com
            Embedded Graphics & GUI library: https://ugfx.io

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              There's no recommendation AFAIK. It depends on your needs and how well each solution fits with the rest of your design.

              Having it separate has the benefit of modularity - you can mix an match them without touching the other. But if your classes are specific to your needs and modularity is not something you're gonna use or need (which is not uncommon) then a compact "umbrella" class could be easier to maintain.
              All in all it's really a detail and doesn't matter that much. Either way will work and you'll see solutions using both approaches out there.

              Joel BodenmannJ 1 Reply Last reply
              1
              • Chris KawaC Chris Kawa

                There's no recommendation AFAIK. It depends on your needs and how well each solution fits with the rest of your design.

                Having it separate has the benefit of modularity - you can mix an match them without touching the other. But if your classes are specific to your needs and modularity is not something you're gonna use or need (which is not uncommon) then a compact "umbrella" class could be easier to maintain.
                All in all it's really a detail and doesn't matter that much. Either way will work and you'll see solutions using both approaches out there.

                Joel BodenmannJ Offline
                Joel BodenmannJ Offline
                Joel Bodenmann
                wrote on last edited by
                #7

                Sounds reasonable. Thank you for your help!

                Industrial process automation software: https://simulton.com
                Embedded Graphics & GUI library: https://ugfx.io

                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