Results 1 to 3 of 3

Thread: Complete Model / View Seperation

  1. #1
    Join Date
    Jun 2015
    Posts
    1
    Qt products
    Qt5

    Default Complete Model / View Seperation

    My colleagues are interested in refactoring a mid-size (15,000 line) application to use a complete separation of Qt from the model. That is to say, the model would not contain any "Q" types at all and would live in a separate directory. A controller would then be used to talk to the view.

    We're used this architecture to good effect in the past, for a real-time application. In this case the threading model was more complex (since it was for real-time apps), so it was advantageous to have the underbelly in pure C++.

    In the case of our current application however I'm not so sure. It's a single-threaded application and most of the data that would be contained in the "model" is view-related data anyway, such as panel positions and widget sizes.

    My question is, how often is a complete separation of model from view an approach that is used in practice for Qt? Is this something you've personally used to good effect?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Qt products
    Qt5
    Platforms
    MacOS X
    Thanks
    13
    Thanked 153 Times in 150 Posts

    Default Re: Complete Model / View Seperation

    Unless I'm misunderstanding your post, the Qt model/view paradigm already separates the data from the view. i.e. The model is responsible for the data and the view is how you wish to visually represent the data. Qt allows multiple views to operate on the same model and you can even show those multiple views separately at the same time.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Complete Model / View Seperation

    My question is, how often is a complete separation of model from view an approach that is used in practice for Qt? Is this something you've personally used to good effect?
    As jefftee says, Qt's model / view paradigm already implements a complete separation of models and views. If what you really mean is, "Is it possible to implement a model completely independently of Qt and use it in the Qt model / view architecture", the answer to that is yes, too.

    I have a large pure C++ computational program that produces results as an instance of a plain vanilla C++ class structure. In the UI, I interface this to a model derived from QAbstractItemModel in order to display the results (through a set of proxy models) in a QTreeView, QTableView, and numerous graphical plots. The trick is that you need a way to tell the Qt model that the C++ model has changed. You don't have to expose the Qt paradigm to your C++ class, but simply implement a callback mechanism that lets the C++ model tell the Qt model something's changed. The Qt model can then issue signals to notify views to update their contents.

    In my case, I store a pointer to the C++ class in my Qt model class, and override the data() method to retrieve the C++ model content and map it into Qt model items.

Similar Threads

  1. Replies: 4
    Last Post: 18th April 2012, 19:11
  2. Replies: 0
    Last Post: 21st April 2010, 13:23
  3. Replies: 1
    Last Post: 1st February 2010, 19:42
  4. QSql Model-View: How to keep view in sync with model
    By schall_l in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 00:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.