Question

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

Was it helpful?

Solution

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

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

Triggered, not trigerred! :)

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top