PDA

View Full Version : Close event in QMdiSubWindow



bxaHj
22nd May 2009, 08:37
Hi,
i have a problem catch the closing event in in subwindow.
Here is my source code:

mainwindow.cpp


void MainWindow::newMdiChild()
{
qDebug() << "MainWindow::newMdiChild()";

tcache.newWindow();
QWidget *widget = new QWidget(ui->mdiArea);
QVBoxLayout *layout = new QVBoxLayout(widget);

mdiForm *mForm = new mdiForm(this);
layout->addWidget(mForm);
widget->setLayout(layout);
QMdiSubWindow *subWindow = ui->mdiArea->addSubWindow(widget);
subWindow->resize(600,600);
subWindow->setAttribute(Qt::WA_DeleteOnClose);
subWindow->setWindowTitle("");
subWindow->show();
//...
}

mdiform.cpp


#include "mdiform.h"
#include "ui_mdiform.h"
#include <QtCore/QtDebug>
mdiForm::mdiForm(QWidget *parent) :
QWidget(parent),
m_ui(new Ui::mdiForm)
{
m_ui->setupUi(this);
}
void mdiForm::closeEvent(QCloseEvent *event)
{
qDebug() << "mdiForm::closeEvent()";
}
mdiForm::~mdiForm()
{
delete m_ui;
}

mdiform.h


#ifndef MDIFORM_H
#define MDIFORM_H
#include <QtGui/QWidget>
#include <QtGui/QCloseEvent>
#include "ui_mdiform.h"
namespace Ui {
class mdiForm;
}
class mdiForm : public QWidget {
Q_OBJECT
Q_DISABLE_COPY(mdiForm)
public:
explicit mdiForm(QWidget *parent = 0);
virtual ~mdiForm();
Ui::mdiForm *m_ui;

protected:
virtual void closeEvent(QCloseEvent *event);

};
#endif // MDIFORM_H

Can you help me to find a solution for this?

fnmblot
26th May 2009, 21:18
protected:
void closeEvent(QCloseEvent *event);

If there isn't a difference in what to do when accepted or rejected, just connect them both to a certain slot.