1.
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w1;
w1.show();
QWidget w2;
w2.show();
return a.exec();
}
此时,两个窗口都关闭后,xxx.exe退出(任务管理器中xxx.exe消失)。
2.
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w1;
w1.show();
QWidget *w2=new QWidget;
w2->show();
//存在内存泄漏
return a.exec();
}
存在内存泄漏。
但两个窗体关闭后,xxx.exe退出。
3.
#include "widget.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QWidget *w=new QWidget;
w->setWindowTitle("www");
w->show();
}
Widget::~Widget()
{
delete ui;
}
结果:还是存在内存泄漏,但关闭两个窗体后,xxx.exe仍然退出啦。
Qt窗口关闭 应用进程不退出_qt程序关闭后进程还在-CSDN博客
跟这篇文章的描述不一样?