The sender is an anonymous action here, which is created by the menu. If you want to identify it, you have to create a QAction object yourself and add it to the menu using QAction::addTo(). Only then you'll be able to identify the action. But tell me, why do you want to identify the action at all? If you want to have a bunch of if blocks calling different functions in the slot, maybe it's simpler to have separate slots for each of them? Or if they contain hierarchical actions, call them directly one from the other like so:
menu->insertItem("Save", this, SLOT(save()));
menu->insertItem("Save As", this, SLOT(saveAs()));
//...
void X::save(){
//...
}
void X::saveAs(){
if(!fname.isEmpty()){
m_filename = fname;
save(); // call the "lower level" slot
}
}
menu->insertItem("Save", this, SLOT(save()));
menu->insertItem("Save As", this, SLOT(saveAs()));
//...
void X::save(){
//...
}
void X::saveAs(){
QString fname = QFileDialog::getSaveFileName();
if(!fname.isEmpty()){
m_filename = fname;
save(); // call the "lower level" slot
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks