To create a nested QAbstractListModel containing a QAbstractListModel



  • I have a structure i.e., Menu containing sub menu
    I'm creating the ListModel in Qt subclassing the QAbstractListModel

    Here's the code

    class MenuItem;
    
    class MenuModel : public QAbstractListModel
    {
        Q_OBJECT
    public:
        enum MenuRoles {
            NameRole = Qt::UserRole + 1
        };
    
        MenuModel(QObject *parent = 0);
    
        void addMenu(const MenuItem &menuitem);
    
        int rowCount(const QModelIndex & parent = QModelIndex()) const;
    
        QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
    
    protected:
        QHash<int, QByteArray> roleNames() const;
    
    private:
        QList<MenuItem> m_menuItems;
    };
    
    class MenuItem
    {
    public:
        explicit MenuItem();
        ~MenuItem();
        void setName(QString name);
    private:
        QString             m_strName;
        MenuModel           m_subMenuModel;
    };
    
    

    However I get compile time error saying " error: C2248: 'QAbstractListModel::QAbstractListModel' : cannot access private member declared in class 'QAbstractListModel' "

    Is it possible to structure this way? or is there a better way?


  • Lifetime Qt Champion

    Hi,

    Where are you getting that error ?



  • at line

    QList<MenuItem> m_menuItems;
    

  • Lifetime Qt Champion

    What private member are you trying to access ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.