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. Models and Views - Best practice

Models and Views - Best practice

Scheduled Pinned Locked Moved General and Desktop
modelview
2 Posts 2 Posters 1.1k 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.
  • I Offline
    I Offline
    idlefrog
    wrote on 11 Mar 2015, 14:04 last edited by idlefrog 3 Nov 2015, 14:09
    #1

    A general question regarding models and views, and my simple model-view design:

    Lets say we have a model class containing an assortment of dissimilar data members, (equivalent to a table, with one row, and multiple columns). It has a 'changed()' signal.

    A custom view has this as its model. It has a slot called update() that connects to the changed() signal.
    The view is made up of an assortment of string edits, and checkboxes.
    The view updates the model if the user changes the contents of any widget.

    The question is, should I always inherit QStandardItemModel / QAbstractItemModel as a starting point for such
    a custom data model? Is this not over engineering? What if the data members are of a complex class type?

    So Is it good enough to just implement a a few change signals, and update the view accordingly?
    What does seem awkward about this simple solution, is that the view's update() method has to disconnect its assortment of widgets from itself, and then reconnect once update() is finished.

    What is best practice?
    What are people's opinion on this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 11 Mar 2015, 15:59 last edited by
      #2

      I think QAbstractItemModel and friends is a winner here. It contains a lot of optimized functions, that allow you to update single cells instead of invalidating the view, reconnecting the widgets, etc. It also allows you to leverage all the more advanced mechanisms like lazy initialization (canFetchMore() and fetchMore() methods).

      (Z(:^

      1 Reply Last reply
      0

      2/2

      11 Mar 2015, 15:59

      • Login

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