Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Model/View data access



  • The data access interfaces in the QAbstractItemModel class force the subclasses to use QVariant when getting/setting data to the model.

    There are two ways to access the internal data of my model:

    • Use Q_DECLARE_METATYPE macro for all of my internal data classes so they can be used with QVariant.

    OR

    • Add my custom data access methods. (custom get/set functions).

    Which one is reasonable with the expected use of Qt Model/View.



  • Add my custom data access methods. (custom get/set functions).

    This also requires the delegate to get tied up with the model.

    I'm a fan of solution 1 but, in the interest of pragmatism, I'd say use the path that is less painful to implement for you.

    P.S.
    Classes that include the Q_GADGET macro are already registered metatypes so you can go down that route as well


Log in to reply