I need to force act to be fileSaveAction; but don't work; I put fileSaveas action inside popupMenu (mouse menu); so when I click on filesaveas on popupmenu SLOT starts but the sender() must be fileSaveAs...thanks
Printable View
I need to force act to be fileSaveAction; but don't work; I put fileSaveas action inside popupMenu (mouse menu); so when I click on filesaveas on popupmenu SLOT starts but the sender() must be fileSaveAs...thanks
Wouldn't the handling be easier, and more importantly, much more clear if you had separate slots for different saving actions? Anyway, if you really want something like this, put the actions in a group and connect the group's selected(QAction*) to that slot and you'll get the according source action as a parameter.
mmm my problem is this: when the SLOT below is called, I'd like a way to know, inside filesaveAs, who's the caller (ie myPopupmenu)
Code:
"&Save As", w, SLOT(fileSaveAs()), CTRL+Key_A );
But what exactly is the problem? Sender() should return the object emitting the signal... What exactly are you trying to achieve?
the problem is if I invoke saveAs SLOT with "mypopupMouseMenu" it starts but act is not == fileSaveAsAction; this is the problem;Quote:
Originally Posted by mickey
What exactly do you mean by "invoke"? If you call a slot yourself (and not trigger through signal emition), sender() won't return a valid value. Could you show us the connect statement responsible for the signal-slot connection?
with this SLOTfileSaveAs() is called; but I need to know, inside this SLOT, who's the sender...How do I capture the sender() in this case? thanksQuote:
Originally Posted by mickey
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:
Code:
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 } }