One more doubt. I managed to set the submenu and return using
Declaration
MenuModel *subMenu();
MenuModel *subMenu();
To copy to clipboard, switch view to plain text mode
Definition
MenuModel* MenuItem::subMenu()
{
return &m_subMenuModel;
}
MenuModel* MenuItem::subMenu()
{
return &m_subMenuModel;
}
To copy to clipboard, switch view to plain text mode
Now I need to set the role and return using the function
{
if (index.row() < 0 || index.row() >= m_menuItems.count())
MenuItem *menu = m_menuItems[index.row()];
switch (role) {
case NameRole:
return menu->menuName();
case SubMenuRole:
return menu->subMenu();
default:
break;
}
}
QVariant MenuModel::data(const QModelIndex & index, int role) const
{
if (index.row() < 0 || index.row() >= m_menuItems.count())
return QVariant();
MenuItem *menu = m_menuItems[index.row()];
switch (role) {
case NameRole:
return menu->menuName();
case SubMenuRole:
return menu->subMenu();
default:
return QVariant();
break;
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
But i get the error on line "return menu->subMenu();" saying "error: C2248: 'QVariant::QVariant' : cannot access private member declared in class 'QVariant'"
Kindly advice what i'm missing
Bookmarks