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. To create a nested QAbstractListModel containing a QAbstractListModel

To create a nested QAbstractListModel containing a QAbstractListModel

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.4k 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.
  • V Offline
    V Offline
    Valerian
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Where are you getting that error ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Valerian
        wrote on last edited by
        #3

        at line

        QList<MenuItem> m_menuItems;
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What private member are you trying to access ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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