mastupristi
26th November 2009, 13:44
Suppose I have the following code
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QDialog>
class MainWindow : public QDialog
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent)
: QDialog(parent)
{
QHBoxLayout *mainLayout = new QHBoxLayout(this);
QHBoxLayout *slaveLayout = new QVBoxLayout(this);
slaveLayout->addWidget(new QLabel("A0"));
slaveLayout->addWidget(new QLabel("A1"));
mainLayout->addLayout(slaveLayout);
mainLayout->addWidget(new QLabel("B0"));
setLayout(mainLayout);
}
MainWindow::~MainWindow()
{
delete layout();
}
does the destrictor delete both mainLayout and slaveLayout?
Or do I need to modify as follows:
MainWindow::~MainWindow()
{
delete layout()->layout();
delete layout();
}
thanks
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QDialog>
class MainWindow : public QDialog
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent)
: QDialog(parent)
{
QHBoxLayout *mainLayout = new QHBoxLayout(this);
QHBoxLayout *slaveLayout = new QVBoxLayout(this);
slaveLayout->addWidget(new QLabel("A0"));
slaveLayout->addWidget(new QLabel("A1"));
mainLayout->addLayout(slaveLayout);
mainLayout->addWidget(new QLabel("B0"));
setLayout(mainLayout);
}
MainWindow::~MainWindow()
{
delete layout();
}
does the destrictor delete both mainLayout and slaveLayout?
Or do I need to modify as follows:
MainWindow::~MainWindow()
{
delete layout()->layout();
delete layout();
}
thanks