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