habbas33
28th September 2016, 12:41
Hi.. I have make a simple project and try to understand destructor. but I
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"
#include "QDebug.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug()<<"start MainWindow";
}
MainWindow::~MainWindow()
{
delete ui;
qDebug()<<"end MainWindow";
}
void MainWindow::on_pushButton_clicked()
{
Dialog *dia = new Dialog;
dia->show();
}
#include "dialog.h"
#include "ui_dialog.h"
#include "QDebug.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
qDebug()<<"start Dialog";
}
Dialog::~Dialog()
{
delete ui;
qDebug()<<"end Dialog";
}
The problem is that when I close qDialog... it doesnot goes to the ~dialog and print "end dialog"....
however, when I close mainWindow... goes to the ~mainWindow and print end mainWindow....
Please tell me how to go to the destructor for dialog and the reason behind it....
Best Regards,
Haider
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"
#include "QDebug.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug()<<"start MainWindow";
}
MainWindow::~MainWindow()
{
delete ui;
qDebug()<<"end MainWindow";
}
void MainWindow::on_pushButton_clicked()
{
Dialog *dia = new Dialog;
dia->show();
}
#include "dialog.h"
#include "ui_dialog.h"
#include "QDebug.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
qDebug()<<"start Dialog";
}
Dialog::~Dialog()
{
delete ui;
qDebug()<<"end Dialog";
}
The problem is that when I close qDialog... it doesnot goes to the ~dialog and print "end dialog"....
however, when I close mainWindow... goes to the ~mainWindow and print end mainWindow....
Please tell me how to go to the destructor for dialog and the reason behind it....
Best Regards,
Haider