0
所以,我试图在QT Creator中运行我的电子表格应用程序,它编译时没有错误,但是当我尝试运行该应用程序时,出现以下错误QWidget::insertAction Attempt to insert null action
。问题是我不知道问题来自哪里......错误不会出现在QT Creator的错误部分,而是在运行程序时创建的小终端中。QWidget :: insertAction尝试在运行时插入空动作
我有一个createActions()
函数,用于初始化标题中启动的所有动作,可能是从那里来的?
在头的私处的动作是这样的:
QAction *newAction;
QAction *openAction;
QAction *aboutQtAction;
QAction *closeAction;
QAction *exitAction;
QAction *selectAllAction;
QAction *showGridAction;
QAction *saveAction;
QAction *saveAsAction;
QAction *cutAction;
QAction *copyAction;
QAction *pasteAction;
QAction *deleteAction;
QAction *selectRowAction;
QAction *selectColumnAction;
QAction *findAction;
QAction *goToCellAction;
QAction *recalculateAction;
QAction *sortAction;
QAction *autoRecalcAction;
QAction *aboutAction;
这里的功能:
void MainWindow::createActions()
{
newAction = new QAction(tr("&New"), this);
newAction->setIcon(QIcon(":/images/avatar.jpeg"));
newAction->setShortcut(QKeySequence::New);
newAction->setStatusTip(tr("Create a new spreadsheet file"));
connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
for (int i = 0; i < MaxRecentFiles; ++i) {
recentFileActions[i] = new QAction(this);
recentFileActions[i]->setVisible(false);
connect(recentFileActions[i], SIGNAL(triggered()),this, SLOT(openRecentFile()));
}
closeAction = new QAction(tr("&Close"), this);
closeAction->setShortcut(QKeySequence::Close);
closeAction->setStatusTip(tr("Close this window"));
connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
exitAction = new QAction(tr("E&xit"), this);
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("Exit the application"));
connect(exitAction, SIGNAL(triggered()),
qApp, SLOT(closeAllWindows()));
selectAllAction = new QAction(tr("&All"), this);
selectAllAction->setShortcut(QKeySequence::SelectAll);
selectAllAction->setStatusTip(tr("Select all the cells in the "
"spreadsheet"));
connect(selectAllAction, SIGNAL(triggered()),
spreadsheet, SLOT(selectAll()));
showGridAction = new QAction(tr("&Show Grid"), this);
showGridAction->setCheckable(true);
showGridAction->setChecked(spreadsheet->showGrid());
showGridAction->setStatusTip(tr("Show or hide the spreadsheet's "
"grid"));
connect(showGridAction, SIGNAL(toggled(bool)),
spreadsheet, SLOT(setShowGrid(bool)));
aboutQtAction = new QAction(tr("About &Qt"), this);
aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
这些行动,在被创建后,被添加到菜单中createMenus()
功能:
void MainWindow::createMenus(){
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAction);
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addAction(saveAsAction);
separatorAction = fileMenu->addSeparator();
for (int i = 0; i < MaxRecentFiles; ++i)
fileMenu->addAction(recentFileActions[i]);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
...
有人有任何想法,这个错误来了f只读存储器?
谢谢! 阿克塞尔
我的不好,这个动作是在头文件中初始化的,不好添加相关部分。 – Axel 2012-03-10 22:06:00
@Axel你刚刚添加的东西 - 指针在头文件中被定义*你在哪里做'saveAction = new QAction()'?那是他们得到*创建的时候* – tmpearce 2012-03-10 22:11:47
哦,刚刚意识到某些动作从未实现过,这很有趣,因为我强硬的那些错误会在编译为错误时弹出。所以我有点惊讶他们没有在错误输出面板中显示错误QTCreator oo – Axel 2012-03-10 22:21:17