gpt4 book ai didi

c++ - QWidget::insertAction 尝试在运行时插入空操作

转载 作者:行者123 更新时间:2023-11-28 08:08:40 25 4
gpt4 key购买 nike

所以,我尝试在 QT Creator 中运行我的电子表格应用程序,它编译时没有错误,但是当我尝试运行该应用程序时,我收到以下错误 QWidget::insertAction Attempt to insert null action。问题是我不知道问题出在哪里...错误不是出现在 QT Creator 的错误部分,而是出现在运行程序时创建的小终端中。

我有一个 createActions() 函数可以初始化 header 中初始化的所有操作,也许是从那里来的?

header 的私有(private)部分中的操作如下所示:

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

有人知道这个错误是从哪里来的吗?

谢谢!阿克塞尔

最佳答案

createActions() 中,您似乎没有初始化 openActionsaveActionsaveAsAction - 然后将其插入菜单。我猜这就是问题所在,除非您不包含初始化这些特定操作的代码。

关于c++ - QWidget::insertAction 尝试在运行时插入空操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9650501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com