QAction, triggered signal dont call a slot
Hello,
I have QMainWindow and i created a QMenuBar added QMenu in it with actions that are connected with some slots but when i run appliacation and want to use some options from menu the slot is not called, i dont know where is a problem.
Here is main window constructor
Code:
ui(new Ui::Window)
{
setCentralWidget(ui->centralWidget);
ui->setupUi(this);
ui->render = new Render();
ui
->menuAnimacja
= new QMenu;
createAnimationActions();
ui->menuAnimacja->addAction( ui->actionStart );
ui->menuAnimacja->addAction( ui->actionStop );
ui->menuBar->addMenu( ui->menuAnimacja );
}
and here i am creating actions
Code:
void Window::createAnimationActions()
{
ui
->actionStart
= new QAction(this);
connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(startAnimation()));
ui
->actionStop
= new QAction(this);
connect(ui->actionStop, SIGNAL(triggered()), this, SLOT(stopAnimation()));
}
Re: QAction, triggered signal dont call a slot
Do you get any warnings at the console?
Re: QAction, triggered signal dont call a slot
Re: QAction, triggered signal dont call a slot
Could you show us the declaration of your Window class?
Re: QAction, triggered signal dont call a slot
Code:
ui
->actionStart
= new QAction(this);
:confused: why are you do that? The ui file has already create one. Also setting a central widget in the ctor before calling ui->setupUi() is "nonsens". So most likely you are doing some other things which break the connection. To figure that out, please provide a minimal compilable example reproducing your problem.
EDIT: Ha! I think because you create a new action you can't trigger it through your created menu anymore.
Re: QAction, triggered signal dont call a slot
There is more of that. This doesn't make sense too:
Code:
ui->menuBar->addMenu( ui->menuAnimacja );
Re: QAction, triggered signal dont call a slot