QWidget::insertAction尝试在运行时插入null操作
QWidget::insertAction Attempt to insert null action at runtime
因此,我试图在QT Creator中运行我的电子表格应用程序,它编译时没有错误,但当我尝试运行该应用程序时,我会收到以下错误QWidget::insertAction Attempt to insert null action
。问题是我不知道这个问题是从哪里来的。。。该错误不会出现在QT Creator的错误部分,而是出现在运行程序时创建的小终端中。
我有一个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);
...
有人知道这个错误是从哪里来的吗?
谢谢!Axel
在createActions()
中,您似乎没有初始化openAction
、saveAction
或saveAsAction
,然后将其插入到菜单中。我想这就是问题所在,除非您没有包含初始化这些特定操作的代码。
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 预处理器:插入结构名称中的前一个行号
- 在未初始化映射的情况下,将值插入到映射的映射中
- 如何在c++中只将键插入到bimap的一侧
- 如何将结构插入到集合中并打印集合的成员
- C++json插入数组
- Visual Studio 2019:插入多个C++风格的单行注释
- nlohmann-json将一个数组插入到另一个数组中
- 无法在我的链接列表中插入项目,head始终为NULL
- 具有 4 个指针的节点的递归插入函数返回 null
- C ado.net无法将值null插入列中
- 使用libpqxx库插入null/空字符串
- QWidget::insertAction尝试在运行时插入null操作
- C++:为链表实现插入函数,prev_ptr最终为NULL
- 正在插入Trie,NULL指针
- C++ Stl 矢量插入空 (NULL) 节点
- 通过操作符[]在map中插入指针类型的值总是NULL
- ADO 命令说我正在插入 NULL,而我没有
- 插入无序映射将共享ptr变为null