#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
qDebug() << this << "created";
connect(pb, SIGNAL(clicked()), this, SLOT(hide()));
layout->addWidget(pb);
setLayout(layout);
}
~Dialog() {
qDebug() << this << "destroyed";
}
protected:
void closeEvent
(QCloseEvent *e
) { qDebug
() <<
this <<
"closeEvent called";
} };
Q_OBJECT
public:
connect(pb, SIGNAL(clicked()), this, SLOT(openDialog()));
setCentralWidget(pb);
}
~MainWindow() { qDebug() << "MainWindow destroyed:" << this; }
public slots:
void openDialog() {
if (!dialog)
dialog = new Dialog(this);
dialog->show();
}
protected:
qDebug() << this << "closeEvent called";
}
private:
Dialog *dialog;
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class Dialog: public QDialog {
Q_OBJECT
public:
Dialog(QWidget *p = 0): QDialog(p) {
qDebug() << this << "created";
QPushButton *pb = new QPushButton("Hide Me", this);
connect(pb, SIGNAL(clicked()), this, SLOT(hide()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(pb);
setLayout(layout);
}
~Dialog() {
qDebug() << this << "destroyed";
}
protected:
void closeEvent(QCloseEvent *e) { qDebug() << this << "closeEvent called"; }
};
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p), dialog(0) {
QPushButton *pb = new QPushButton("Show dialog", this);
connect(pb, SIGNAL(clicked()), this, SLOT(openDialog()));
setCentralWidget(pb);
}
~MainWindow() { qDebug() << "MainWindow destroyed:" << this; }
public slots:
void openDialog() {
if (!dialog)
dialog = new Dialog(this);
dialog->show();
}
protected:
void closeEvent(QCloseEvent *e) {
qDebug() << this << "closeEvent called";
}
private:
Dialog *dialog;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks