Results 1 to 4 of 4

Thread: Application design using MVC

  1. #1

    Default Application design using MVC

    This is a hypothetical although it could apply to any number of programs I'm working on at the moment.

    Say my program is based around displaying and editing data in a database and I use the active record pattern for classes representing the data in the database. Single entities are accessed via a list for which I would use a QSqlTableModel and QTableView to display.

    My question is, to keep with the pattern should I use QSqlTableModel directly or should I subclass QAbstractItem/ListModel and implement say a CompanyListModel (if I used it to list companies from the database) which would internally use a QSqlQuery to instantiate a list of Company objects? Would this be considered good design or is it just overkill?

    TIA

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application design using MVC

    IMO you just need to adjust the delegate to return an editor like a combobox that allows you to choose from a list of options.

  3. #3

    Default Re: Application design using MVC

    Thanks but I don't think that was the answer I was looking for. I'll try and explain myself a bit better.

    We have a program at work that displays companies we deal with, their addresses and contacts, which are stored in a database. At the moment it's design doesn't follow a pattern - when inserting or editing data the additton or changes are made using a query that is instantiated in the onclick event of an ok button.

    Inserting or editing data can easily be changed to use the active record pattern where the properties and functions to load and save a company, address or contact are encapsulated in their own classes. This would mean that in the onclick event of the ok button we can now instantiate a Company and call Company::save() to save it to the database.

    My question is, in keeping with good design and using patterns, when listing all companies should I use a QSqlQueryModel which selects * from company and displays it in a QTableView, or should I subclass QAbstractItem/ListModel in such a way so that internally it keeps a list of Company objects which it has loaded from the database?

    I hope that's a bit clearer.

    TIA
    Mark

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application design using MVC

    You should use QSqlTableModel or QSqlRelationalTableModel and QDataWidgetMapper. If you can't have a table (or a database view) that carries all the data you need, then either implement a proxy model or a classic model based on QSqlQueryModel (implement write capabilities).

Similar Threads

  1. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  2. Application deployment problem
    By shapirlex in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 13th April 2007, 00:11
  3. Replies: 3
    Last Post: 8th December 2006, 18:51
  4. application design questions
    By nikita in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2006, 00:35

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.