QAction不会连接到我的插槽

0 c++ qt signals-slots qmenu

我正在尝试用Qt制作IHM,我开始制作一个基本菜单(文件,编辑......).到目前为止,我的菜单包含"文件",然后显示"新建项目,打开项目,退出".看起来很棒,但我的问题是我似乎无法触发这些动作(点击它们或按键快捷键).

这是我的插槽:

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

如果我在连接按钮时使用此插槽,我的新QWidget会正确显示.但是,动作不可能做同样的事情......

这是我的行为和菜单的代码:

    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");
Run Code Online (Sandbox Code Playgroud)

}

    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()));
Run Code Online (Sandbox Code Playgroud)

}

以及使用按钮的代码:

connect(m_button, SIGNAL(clicked()), this, SLOT(launchNewProjectWidget()));
Run Code Online (Sandbox Code Playgroud)

所以我真的不明白为什么它不应该反应一样,我一遍又一遍地阅读Qt的例子......我一定错过了一些东西,但如果有人作为一个想法,我将不仅仅是感激,它开始让我讨厌生活:p

谢谢你们.

PS:好的,不确定我处理好代码块的商务,在我的辩护中使用它真的很奇怪...:p

Blo*_*ood 5

你在触发的词中犯了错误:P它应该是:

connect(m_quitAction, SIGNAL(triggered()), this, SLOT(quit()));
                                ------
Run Code Online (Sandbox Code Playgroud)

触发,而不是trigerred!:)