PDA

View Full Version : Enabling/Disabling QActions in QMenus



rshabsin
15th February 2006, 21:05
I'm converting Qt3 code to Qt4 on Linux, and am having a weird problem. I create QActions and add them to a menu using:

RemoveAllAction = new QAction(this);
RemoveAllAction->setText(tr("Re&set All"));
RemoveAllAction->setToolTip(tr("Reset everything"));
RemoveAllAction->setShortcut(QKeySequence(tr( "Alt+S" )));
connect( RemoveAllAction, SIGNAL(triggered()), this, SLOT(RemoveAllAction_activated()));
...
optionsMenu = new QMenu(this);
clearMenu = new QMenu(this);
clearMenu->addAction(RemoveAllAction);
RemoveAllAction->setEnabled(false);
clearMenu->setTitle("Clear");
optionsMenu->addMenu(clearMenu);
...
menuBar()->addMenu(optionsMenu);

When I try to enable the RemoveAllAction QAction later using RemoveAllAction->setEnabled(true), I get a segmentation fault! If I comment out the line that does the disable, the code runs OK. I have several other actions that act the same way I initially thought it might have something to do with the fact that the QAction is in a sub-menu, but since it works OK when I comment out the initial disable (or change the second setEnabled to false). I don't think so. I've spent many hours on this already :confused: ! Any ideas?

naresh
15th February 2006, 21:57
Can you put more code? I've made same thing as you (disable action at init, and enable it when i want) w/o seg fault and can't see whats wrong is now

jacek
15th February 2006, 22:03
Maybe you have defined RemoveAllAction variable in more than one place?

rshabsin
15th February 2006, 22:13
I really don't know what more code I could put in. It's basically all there. There are a few other QActions, etc., but I don't think that would matter. It's really straightforward. I am in the middle of converting to Qt4. I wonder if there's some conflict going on between the Qt4 libraries and the Qt3Support libraries.

RemoveAllAction is only defined in my .h file, nowhere else.