PDA

View Full Version : QAction, triggered signal dont call a slot



kaszewczyk
5th October 2010, 20:24
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


Window::Window(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Window)
{
ui->centralWidget = new QWidget;
setCentralWidget(ui->centralWidget);
ui->setupUi(this);
ui->render = new Render();

ui->menuBar = new QMenuBar;

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


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()));
}

wysota
5th October 2010, 20:55
Do you get any warnings at the console?

kaszewczyk
5th October 2010, 21:14
No warns at all

wysota
5th October 2010, 21:16
Could you show us the declaration of your Window class?

Lykurg
5th October 2010, 21:18
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.

wysota
5th October 2010, 21:19
There is more of that. This doesn't make sense too:

ui->menuBar->addMenu( ui->menuAnimacja );

kaszewczyk
5th October 2010, 21:30
Thanks, guys :)