vendredi 5 avril 2019

For-based loop for large number of QMenus

being a noobie with Qt I couldn't figure out how to create a vector of QMenu.

Using C++ I got the following (simple) idea:

std::vector<QMenu> *subMenus;

and then use a for-loop to create a certain number of menus.

for (int i = 0; i < List.size(); ++i)
{
   subMenus[i] = new QMenu('some name',MainMenu);
   MainMenu->addMenu(subMenus[i]);
}

Where the size of List is a large number (~40). The problem is that in doing this I face the following error message refering to the index i:

expression must have a constant value.

I am not sure if I should use append or push back to subMenus to avoid this error.

Thanks

Aucun commentaire:

Enregistrer un commentaire