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. Multiple inheritance from QOBject. New Issue related
Forum Updated to NodeBB v4.3 + New Features

Multiple inheritance from QOBject. New Issue related

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

    Hello everyone.

    I read a bit on this topic before posting this. It looks that multiple inheritance from QObject is forbidden unless the inheritance is set as private in all subclasses but one.

    In my project, I use Qt Model/View in Qt 5.14.2 and I have a Model class inheriting from QAbstractListModel. I want to allow selection in my model and I found this useful QItemSelectionModel class I could inherit from, taking advantages of all the features already in place for selection of items in the model. Here it comes the problem, I can't inherit from both QAbstractItemModel and QItemSelectionModel at the same time. I know I can instantiate a QItemSelection object in my model and use that to manage selection but It would be good if QItemSelectionModel worked as an interface to inherit from rendering a model "Selectable".

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Selection is something done on view, not on model. The model should not know whether items are selected or not.

      If in your case model needs to be notified about selection (it's saved to database etc.), you can (ab)use Qt::CheckStateRole property and simply set certain items checked when they are selected.

      (Z(:^

      1 Reply Last reply
      2

      • Login

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