below I quoted my code. The problem is easy to describe. selectedItem->text is not the right way to differ what action was selected in the menu. How to do it right?
void RView::ShowContextMenu(const QPoint& pos) // this is a slot
{
// for most widgets
QPoint globalPos = statusWidget->mapToGlobal(pos);
// for QAbstractScrollArea and derived classes you would use:
// QPoint globalPos = myWidget->viewport()->mapToGlobal(pos);
QMenu myMenu;
myMenu.addAction("first");
myMenu.addAction("second");
QAction* selectedItem = myMenu.exec(globalPos);
if (selectedItem)
{
if(selectedItem->text == "first")
// do something
if(selectedItem->text == "second")
// do other stuff
}
else
{
// nothing was chosen
}
}