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. QObjectList-based Model in c++
Forum Updated to NodeBB v4.3 + New Features

QObjectList-based Model in c++

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 166 Views 2 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by JulienMaille
    #1

    I've been looking and experimenting with the MVC framework offered by Qt for a couple days.
    I built some dummy application, sub-classed QStandardItemModel, plugged it in a QListView and added a QDataWidgetMapper and I was able to add/remove items, edit them, reorder them. Great!
    It all works well, although you quickly have to write your own delegates if you want to do something fancy.

    Now I'm trying to map this to a model with data nested on 2 levels, and items having different properties depending on their type.
    In this example: a list of vehicles and house with a parent owner.

    ├─ Adam
    │  ├─ age: 45
    │  ├─ sex: m
    │  ├─ vehicle
    │  │  ├─ color: blue
    │  │  ├─ wheels: 4
    │  │  └─ mileage: 1000
    │  └─ house
    │     └─ location: Denver
    ├─ Betty
    │  ├─ age: 40
    │  ├─ sex: f
    │  ├─ house
    │  │  └─ location: Atlanta
    │  └─ house
    │     └─ location: Charlotte
    └─ Charly
       ├─ age: 20
       ├─ sex: m
       └─ vehicle
          ├─ color: red
          ├─ wheels: 2
          └─ mileage: 50000
    

    So it seems that the row/column based models don't fit anymore.
    Also a single QDataWidgetMapper will not allow the edition of an owner, a vehicle and a house, since they have different properties.

    Browsing the documentation I found a QML example saying we can "use a QList<QObject*> as a model" exposing the object QProperties as items.
    Is the one and only approach in my use case? Is it possible to do this without QML?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @JulienMaille said in QObjectList-based Model in c++:

      So it seems that the row/column based models don't fit anymore.

      Why not? What you store in the knots is up to you.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      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