【发布时间】:2012-09-09 00:04:25
【问题描述】:
我正在尝试使用 Qt 制作 IHM,我首先制作了一个基本菜单(文件、编辑...)。 到目前为止,我的菜单包含“文件”,然后显示“新建项目,打开项目,退出”。 看起来不错,但我的问题是我似乎无法触发这些操作(单击它们或通过快捷键)。
这是我的位置:
void KoriganEngine::launchNewProjectWidget(){
//External QWidget
m_nwProj = new NewProjectWidget(NULL,Qt::MSWindowsFixedSizeDialogHint);
m_nwProj->show();
}
如果我在连接按钮的情况下使用此插槽,我的新 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");
}
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()));
}
以及与按钮一起使用的代码:
connect(m_button, SIGNAL(clicked()), this, SLOT(launchNewProjectWidget()));
所以我真的不明白为什么它不应该做出同样的反应,我一遍又一遍地阅读 Qt 示例......我一定错过了一些东西,但如果有人作为一个想法,我会超过感激,因为它开始让我讨厌生活:p
谢谢大家。
PS:好的,我不确定我是否能很好地处理代码块业务,在我的辩护中,使用它真的很奇怪......:p
【问题讨论】:
标签: c++ qt signals-slots qmenu