Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
qt creator 5.3版:如果一个主窗口关闭,则退出整个应用程序_Qt_Definition_Quit_Close Application - Fatal编程技术网

qt creator 5.3版:如果一个主窗口关闭,则退出整个应用程序

qt creator 5.3版:如果一个主窗口关闭,则退出整个应用程序,qt,definition,quit,close-application,Qt,Definition,Quit,Close Application,我试图使用QCloseEvent关闭所有对话框,并在主窗口关闭时退出应用程序。我已经阅读了文档并查看了许多示例,到目前为止我已经想到了以下内容: 在my.h文件中: protected: void mainwindow::closeEvent(QCloseEvent * ); 在my mainwindow.cpp文件中: class QCloseEvent; void mainwindow::closeEvent(QCloseEvent *event) { event->acc

我试图使用QCloseEvent关闭所有对话框,并在主窗口关闭时退出应用程序。我已经阅读了文档并查看了许多示例,到目前为止我已经想到了以下内容:

在my.h文件中:

protected:

void mainwindow::closeEvent(QCloseEvent * );
在my mainwindow.cpp文件中:

class QCloseEvent;
void mainwindow::closeEvent(QCloseEvent *event)
{
    event->accept();

    if (event->isAccepted())
    {
        QApplication::quit();
    }

}
运行此代码时,会出现以下错误: mainwindow::closeEvent”:本地函数定义非法
mainwindow.cpp13:此行包含一个尚未匹配的“{”字符

您的.h文件中的函数声明有问题:

void mainwindow::closeEvent(QCloseEvent * );
应该是:

void closeEvent(QCloseEvent * );

还包括QCloseEvent而不是类QCloseEvent;

我按照建议更改了头文件,但仍然得到以下错误mainwindow.cpp:22:错误:C2601:'mainwindow::closeEvent':本地函数定义是非法的simmotioncontrol.cpp13:此行包含'{'尚未匹配…错误显示在我的.cpp文件中,而不是.h文件中,如果这有助于从cpp(类QCloseEvent)中删除前向声明,并将QCloseEvent头包含到您的cpp或h文件中。我也这样做了,现在我得到了与本地函数定义非法之前相同的错误u为您提供帮助void simMotionControl::closeEventQCloseEvent*事件{event->accept;if event->isAccepted{QApplication::quit;}return;}我发现了问题。我刚刚把代码放在brakets ui->setupUithis的后面;我只是把代码放在那些brakets之外