I am not able to clean action items from the QMenu. It is right click context menu. Every item when I right click it will go through following code. I want to delete any existing items on the menu before I add actions again.
I tried to call clear() on menu. It does not work.
Code:
if(pMenu) { pMenu->clear(); disconnect(pMenu,0,0,0); for ( int item = 0; item < m_strItemList.count(); ++item ) { pAction = pMenu->addAction(strArg.arg(m_strItemList[item] )); mapper->setMapping(pAction, 1) connect(pAction, SIGNAL(triggered()), mapper, SLOT(map())); connect(mapper, SIGNAL(mapped(int)), this, SLOT(RunItem(int))); }
Following is Implemnation of Clear() in QMenu.cpp class in Qt Source. I tried to step into it and it never goes through forloop because actions list is empty.
Code:
{ QList<QAction*> acts = actions(); for(int i = 0; i < acts.size(); i++) { #ifdef QT_SOFTKEYS_ENABLED // Lets not touch to our internal softkey actions if(acts[i] == d->selectAction || acts[i] == d->cancelAction) continue; #endif removeAction(acts[i]); if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty()) delete acts[i]; } }
Thanks.
