Reputation: 335
I am implementing run time menu on a button(QPushButton) in my app user has to make choice between ftp and http when he click on upload button.
QMenu menu(this);
menu.addAction("ftp");
menu.addAction("http");
ui.mUploadBtn->setMenu(&menu);
ui.mUploadBtn->showMenu();
My ques is that how could i know which selection user selected or is their any function to get that.
thankyou
Upvotes: 0
Views: 62
Reputation: 3604
One way to catch the result of a menu is to do this :
QAction* action = menu.exec(QCursor::pos());
Then you can use
action->text()==QString("ftp")
To know if the user clicked on "FTP".
So as said by Frank Osterfeld in the comments, you can also create a slot in you class, and connect menu trigger action signal to it :
connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT( sl_OnMenuTriggered(QAction* )));
void sl_OnMenuTriggered(QAction* _action)
{
if(_action->text()=="ftp") ...
}
This is the "non blocking" way.
Upvotes: 1