fullmetalcoder
3rd March 2007, 17:49
In a custom tree model I have enabled context menu handling at node level and the code looks like that :
pMenu = new QMenu("Actions");
setupMenu(pMenu);
QAction *a = pMenu->exec(p);
qDebug("action triggered : %s", a ? qPrintable(a->text()) : "");
//pMenu->deleteLater();
if ( a )
a->trigger();
setupMenu() is a virtual function that is in charge of setting up the menu content :
QAction *a;
a = new QAction(QIcon(":/"), tr("&Remove"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( deleteLater() ) );
m->addAction(a);
m->addSeparator();
a = new QAction(QIcon(":/folder.png"), tr("A&dd folder"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( addFolder() ) );
m->addAction(a);
a = new QAction(QIcon(":/add.png"), tr("Add &file"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( addFile() ) );
m->addAction(a);
a = new QAction(QIcon(":/file.png"), tr("&New file"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( newFile() ) );
m->addAction(a);
m->addSeparator();
a = new QAction(QIcon(":/clear.png"), tr("&Clear"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( clear() ) );
m->addAction(a);
When I play with my model on a QTreeView the context menu gets displayed correctly. Then if I trigger an action by clicking on a menu item I get a correct message on the console output ( i.e : "action triggered : x") but the triggered signal is never emitted (or never forwarded to the slots I have connected to it even when I call trigger() programmatically ...
I'm using Qt 4.2.2 under Linux. Any hints???
pMenu = new QMenu("Actions");
setupMenu(pMenu);
QAction *a = pMenu->exec(p);
qDebug("action triggered : %s", a ? qPrintable(a->text()) : "");
//pMenu->deleteLater();
if ( a )
a->trigger();
setupMenu() is a virtual function that is in charge of setting up the menu content :
QAction *a;
a = new QAction(QIcon(":/"), tr("&Remove"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( deleteLater() ) );
m->addAction(a);
m->addSeparator();
a = new QAction(QIcon(":/folder.png"), tr("A&dd folder"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( addFolder() ) );
m->addAction(a);
a = new QAction(QIcon(":/add.png"), tr("Add &file"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( addFile() ) );
m->addAction(a);
a = new QAction(QIcon(":/file.png"), tr("&New file"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( newFile() ) );
m->addAction(a);
m->addSeparator();
a = new QAction(QIcon(":/clear.png"), tr("&Clear"), m);
connect(a , SIGNAL( triggered() ),
this, SLOT ( clear() ) );
m->addAction(a);
When I play with my model on a QTreeView the context menu gets displayed correctly. Then if I trigger an action by clicking on a menu item I get a correct message on the console output ( i.e : "action triggered : x") but the triggered signal is never emitted (or never forwarded to the slots I have connected to it even when I call trigger() programmatically ...
I'm using Qt 4.2.2 under Linux. Any hints???