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.

Qt Code:
  1. QString strAg = "ITEM %1";
  2. QMenu * pMenu = new QMenu;
  3.  
  4. if(pMenu)
  5. {
  6. pMenu->clear();
  7. disconnect(pMenu,0,0,0);
  8.  
  9. for ( int item = 0; item < m_strItemList.count(); ++item )
  10. {
  11. QAction * pAction = new QAction(pMenu);
  12. pAction = pMenu->addAction(strArg.arg(m_strItemList[item] ));
  13.  
  14. QSignalMapper* mapper = new QSignalMapper(pMenu);
  15. mapper->setMapping(pAction, 1)
  16. connect(pAction, SIGNAL(triggered()), mapper, SLOT(map()));
  17. connect(mapper, SIGNAL(mapped(int)), this, SLOT(RunItem(int)));
  18.  
  19. }
To copy to clipboard, switch view to plain text mode 

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.
Qt Code:
  1. void QMenu::clear()
  2. {
  3. QList<QAction*> acts = actions();
  4.  
  5. for(int i = 0; i < acts.size(); i++) {
  6. #ifdef QT_SOFTKEYS_ENABLED
  7. Q_D(QMenu);
  8. // Lets not touch to our internal softkey actions
  9. if(acts[i] == d->selectAction || acts[i] == d->cancelAction)
  10. continue;
  11. #endif
  12. removeAction(acts[i]);
  13. if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty())
  14. delete acts[i];
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

Thanks.