PDA

View Full Version : QAction



mickey
14th July 2006, 23:22
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


mainform::fileSaveAs()
QAction* act = (QAction*) sender();
if (act != this->fileSaveAction && act != this->fileSaveAsAction)
act = fileSaveAction;
if ((fileSaveAsAction == act)) doSomething //here problem

jpn
15th July 2006, 08:16
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.

mickey
15th July 2006, 14:22
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)


myPopupmenu->insertItem(QPixmap::fromMimeSource("icone215.png"),
"&Save As", w, SLOT(fileSaveAs()), CTRL+Key_A );

wysota
16th July 2006, 09:38
But what exactly is the problem? Sender() should return the object emitting the signal... What exactly are you trying to achieve?

mickey
16th July 2006, 18:26
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


mainform::fileSaveAs()
QAction* act = (QAction*) sender();
if ((fileSaveAsAction == act)) doSomething //here problem

the problem is if I invoke saveAs SLOT with "mypopupMouseMenu" it starts but act is not == fileSaveAsAction; this is the problem;

wysota
16th July 2006, 22:27
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?

mickey
17th July 2006, 02:09
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)


myPopupmenu->insertItem(QPixmap::fromMimeSource("icone215.png"),
"&Save As", w, SLOT(fileSaveAs()), CTRL+Key_A );

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? thanks

wysota
17th July 2006, 09:42
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(){
QString fname = QFileDialog::getSaveFileName();
if(!fname.isEmpty()){
m_filename = fname;
save(); // call the "lower level" slot
}
}