I'm a newer for Qt and C++. And I feel about below:
//1
widget a;
a.show();
//2
widget *b=new widget();
b->show();
And I remember widget class (inherited from QWidget) have default constructor. But if I use it in a button like:
void MainWindow::on_pushButton_clicked()
{
//widget v;
//v.show();
widget *v=new widget();
v->show();
}
The first is shutdown in 10 miliseconds. What cause the difference between them?
Update:
I put this question is because the most popular way to create a windows in qt main is:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
It can work. The .exec()
is a endless loop. So I want to know why it can't work in function...