0

I'm trying to make an IHM with Qt, and I started by making a basic menu (File,Edit...). So far, I have my menu containing "File", which then display "New Project, Open Project, Exit". Look great, but my problem is I can't seem to trigger these Action (clicking them or by key shortcut).

Here is my slot:

void KoriganEngine::launchNewProjectWidget(){
   //External QWidget
   m_nwProj = new NewProjectWidget(NULL,Qt::MSWindowsFixedSizeDialogHint);
   m_nwProj->show();
}

If I use this slot with a pushbutton connected, my new QWidget is displayed properly. However, impossible to do the same thing with an action...

Here is the code of my actions and menu:

    void KoriganEngine::KG_createMenus(){
//init actions
KG_createMenuActions();

//add menu to the bar
m_fileMenu = menuBar()->addMenu("File");
m_fileMenu->addAction(m_newProjAction);
m_fileMenu->addAction(m_openProjAction);
m_fileMenu->addSeparator();
m_fileMenu->addAction(m_quitAction);

m_editMenu = menuBar()->addMenu("Edit");

}

    void KoriganEngine::KG_createMenuActions(){
m_newProjAction = new QAction("New Project...", this);
m_newProjAction->setShortcuts(QKeySequence::New);
m_newProjAction->setStatusTip(QString("Create a new Project"));
connect(m_newProjAction, SIGNAL(trigerred()), this, SLOT(slottest()));

m_openProjAction = new QAction("Open Project...", this);
m_openProjAction->setShortcuts(QKeySequence::Open);
m_openProjAction->activate( QAction::Hover);
connect(m_openProjAction, SIGNAL(trigerred()), this, SLOT(launchNewProjectWidget())); //TODO replace the slots

m_quitAction = new QAction("Exit", this);
connect(m_quitAction, SIGNAL(trigerred()), this, SLOT(quit()));

}

And the code that works with a button:

connect(m_button, SIGNAL(clicked()), this, SLOT(launchNewProjectWidget()));

So I don't really get why it should not react the same, I've read the Qt examples over and over... I must have missed something, but if anyone as an idea, I'll be more than grateful, as it's starting to make me hate life :p

Thank you all.

PS: Ok, not sure I handle great the code blocks buisness, in my defence it's really weird to use... :p

Crumble
  • 5
  • 4

2 Answers2

5

You made a mistake in triggered word :P It should be:

connect(m_quitAction, SIGNAL(triggered()), this, SLOT(quit()));
                                ------

Triggered, not trigerred! :)

Blood
  • 4,126
  • 3
  • 27
  • 37
  • Thank you, I just noticed that, I'm so ashamed, I've lost hours because of a spelling problem... thanks anyway – Crumble Sep 16 '12 at 15:20
0

if I get this right you problem is m_openProjAction->activate( QAction::Hover); which causes QAction to emit hovered() instead of triggered();

xception
  • 4,241
  • 1
  • 17
  • 27
  • You are not right. This function just emits signal, not set it. – Blood Sep 16 '12 at 15:17
  • I thought of that but it wasn't the issue. The real one is explain above. Thanks anyway – Crumble Sep 16 '12 at 15:21
  • yeah, didn't notice the typo so looked for some real coding error, you should run qt apps with a console nearby, that way you'll see warnings when signals or slots can't be connected for whatever reason – xception Sep 16 '12 at 21:54