简体   繁体   English

QAction无法连接到我的插槽

[英]QAction won't connect to my slot

I'm trying to make an IHM with Qt, and I started by making a basic menu (File,Edit...). 我正在尝试使用Qt制作IHM,然后从制作基本菜单(文件,编辑...)开始。 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. 如果在连接了按钮的情况下使用此插槽,则新的QWidget将正确显示。 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 所以我真的不明白为什么它不应该做出同样的反应,我已经一遍又一遍地阅读了Qt的例子……我一定错过了一些东西,但是如果有人作为一个主意,我将不胜感激,因为它开始让我讨厌生活: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 PS:好的,不确定我是否能很好地处理代码块业务,在我的辩护中,使用它真的很奇怪...:p

You made a mistake in triggered word :P It should be: 您在触发词:P中犯了一个错误,应该是:

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

Triggered, not trigerred! 触发,不触发! :) :)

if I get this right you problem is m_openProjAction->activate( QAction::Hover); 如果我正确,你的问题是m_openProjAction-> activate(QAction :: Hover); which causes QAction to emit hovered() instead of triggered(); 这导致QAction发出hovered()而不是Triggered();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM