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. Best practice for a lot of tables: Create one model/view pair for each table OR use only one view and changing its model
Qt 6.11 is out! See what's new in the release blog

Best practice for a lot of tables: Create one model/view pair for each table OR use only one view and changing its model

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 621 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.
  • F Offline
    F Offline
    flosens
    wrote on last edited by
    #1

    I am storing a number of tables which are accessible through a comboBox by their name/ID.
    Only one table is being displayed at a time.
    The data of the table are stored in separate Qt model objects (QStandardItemModel for example).

    Now my question is: Which is the better approach

    a) create for each table a model/tableView pair and use a stackedWidget for switching between the tables when the user selects a table from the comboBox

    or

    b) create only 1 tableView and when the user selects a table from the comboBox use the setModel() function of the view to switch to the selected model/table

    ???

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

      Hi, welcome to devnet.

      "better" depends on how complex your view class is. If it's just a standard QTableView without any customization then go for simplicity - use a single view. If, on the other hand, you' later want to customize the view, e.g. subclass the QTableView and add some customization for particular models, or use special delegates for some of the models then it might be easier to swap views then to adjust all the customizations on model change.
      There's no one answer here.

      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