Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Render nested QAbstractItemModels

Render nested QAbstractItemModels

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 269 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.
  • J Offline
    J Offline
    JustusR
    wrote on last edited by
    #1

    I'm adding Qt support to an upstream C++ library that has its own model types by making the upstream library's existing types inherit QAbstractItemModel with the intention of using these models in a QML application. Everything is going well for the simple models, however some of the upstream classes are nested, and the resulting structure looks something like this:

    class MyClass1 : QAbstractItemModel
    {
        Q_OBJECT
        Q_PROPERTY(int a READ get_a NOTIFY updated_a)
    
    public:    
        enum Roles {
            IDRole = Qt::UserRole + 1,          // QString
            NameRole = Qt::UserRole + 2,        // QString
            SubmodelRole = Qt::UserRole + 3,    // MyClass2*
        };
        
        Q_INVOKABLE bool function1(int, bool);
        int get_a();
        // QAbstractItemModel overridden functions omitted
    
    signals:
        void signal1();
        void updated_a();
    };
    
    class MyClass2 : QAbstractItemModel
    {
        Q_OBJECT
        Q_PROPERTY(QString b READ get_b NOTIFY updated_b)
        Q_PROPERTY(int c READ get_c NOTIFY updated_c)
    
    public:    
        enum Roles {
            AmountRole = Qt::UserRole + 1,      // int
            SubmodelRole = Qt::UserRole + 2,    // MyClass3*
        };
        
        Q_INVOKABLE bool function2(bool);
        QString get_b();
        int get_c();
        // QAbstractItemModel overridden functions omitted
    
    signals:
        void signal2();
        void updated_b();
        void updated_c();
    };
    
    class MyClass3 : QAbstractItemModel
    {
        Q_OBJECT
    
    public:    
        enum Roles {
            DateRole = Qt::UserRole + 1,          // QDateTime
            DescriptionRole = Qt::UserRole + 2,   // QString
        };
        
        Q_INVOKABLE bool function3(QString);
        // QAbstractItemModel overridden functions omitted
    
    signals:
        void signal3();
    };
    

    Is it possible to make a QML page that fully displays a MyClass1 model, including any submodels that may be present?

    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