SIGNAL(triggered()) is not respond
-
Good day every one. Another situation from me.
Where is a conditions of the problem:
@
private:
//...
QMenu *cm;
QAction sendFileAction;
//...Dialog::Dialog(QWidget parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
//...
cm=new QMenu(this);
sendFileAction=new QAction(tr("&Send file"), this);
//...
connect(sendFileAction,SIGNAL(triggered()),this,SLOT(on_context_menu_triggered(QAction)));
//...
}void Dialog::on_context_menu_triggered(QAction *pAction)
{
QString strContextAction = pAction->text().remove("&");
if(strContextAction=="Send file")
{QMessageBox::about(this,"Informtation","'Send file' in context menu was triggered");}
}
@And choosing "Send file" in context menu gives nothing. I read about problems with triggered() signal. Are there any analogues?
There was also an attempt to connect via:
connect(cm,SIGNAL(triggered(QAction*)),this,SLOT(on_context_menu_triggered(QAction*)));but results are same. Any ideas?
Many thanks in advance.
[EDIT: code formatting, please wrap in @-tags, Volker]
-
connect(..) returns a boolean, you might want to check the returned value of connect to see if the connection is established.
also the parameters in your SIGNAL don't match the parameter expected by your SLOT.
-
Thanks a lot! Now it's work! =)
I will don't set SOLVED this by for now, just in case.
-
Glad I could help. BTW if you need the sender of the received signal in your slot you can always do this:
@
QObject* sender = QObject::sender();
// and then cast it to a class (if its known to you)
if(qobject_cast<QObjectSubclass*>(sender) != NULL)
{
qobject_cast<QObjectSubclass*>(sender)->getOrSetWhatYouWant();
}
@In your case like this:
@
void Dialog::on_context_menu_triggered()
{
QObject* sender = QObject::sender();
if(qobject_cast<QAction*>(sender) != NULL)
{
QString strContextAction = qobject_cast<QAction*>(sender)->text().remove("&");
if(strContextAction=="Send file")
{
QMessageBox::about(this,"Informtation","'Send file' in context menu was triggered");
}
}
}
@ -
You just saving me! Thanks you =)