QAction无法连接到我的插槽 [英] QAction won't connect to my slot

查看:299
本文介绍了QAction无法连接到我的插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Qt制作IHM,然后从制作基本菜单(文件,编辑...)开始. 到目前为止,我的菜单包含文件",然后显示新建项目,打开项目,退出". 看起来不错,但我的问题是我似乎无法触发这些操作(单击它们或通过快捷键).

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).

这是我的广告位:

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

如果在连接了按钮的情况下使用此插槽,则新的QWidget将正确显示. 但是,不可能通过动作来做同样的事情...

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

所以我真的不明白为什么它不应该做出同样的反应,我已经一遍又一遍地阅读了Qt示例...我一定错过了一些东西,但是如果有人想,我会比感激不尽,因为它开始让我讨厌生活:p

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

谢谢大家.

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

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

推荐答案

您在触发词:P中犯了一个错误,应该是:

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

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

已触发,而不是触发! :)

Triggered, not trigerred! :)

这篇关于QAction无法连接到我的插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆