Rohit Rathor
11th May 2016, 08:29
Hi everyone,
I am new in Qt and need to close entire application whenever child window close button('x' top of the window title bar) pressed,
I am able to get close event of parent or mainwindow but unable to its child one, I tried everything, if it is possible so let me know how.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QPushButton *button = new QPushButton(this);
button->setText("close");
connect(button, SIGNAL(clicked(bool)), this, SLOT(dialogbox()));
connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(quitM yApp()));
}
void MainWindow :: dialogbox()
{
dialog = new QDialog(this);
dialog->setWindowTitle("button");
dialog->setGeometry(150,150,350,350);
dialog->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
dialog->show();
//QCloseEvent *eve = new QCloseEvent;
//dialog->closeEvent(eve);
}
void MainWindow :: quitMyApp()
{
qDebug()<<"quit the child window";
}
void MainWindow :: childEvent(QChildEvent *eve)
{
// qDebug()<<"child event";
}
void MainWindow :: closeEvent(QCloseEvent *event)
{
qDebug()<<"close event pressed - ";
event->accept();
}
I am new in Qt and need to close entire application whenever child window close button('x' top of the window title bar) pressed,
I am able to get close event of parent or mainwindow but unable to its child one, I tried everything, if it is possible so let me know how.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QPushButton *button = new QPushButton(this);
button->setText("close");
connect(button, SIGNAL(clicked(bool)), this, SLOT(dialogbox()));
connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(quitM yApp()));
}
void MainWindow :: dialogbox()
{
dialog = new QDialog(this);
dialog->setWindowTitle("button");
dialog->setGeometry(150,150,350,350);
dialog->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
dialog->show();
//QCloseEvent *eve = new QCloseEvent;
//dialog->closeEvent(eve);
}
void MainWindow :: quitMyApp()
{
qDebug()<<"quit the child window";
}
void MainWindow :: childEvent(QChildEvent *eve)
{
// qDebug()<<"child event";
}
void MainWindow :: closeEvent(QCloseEvent *event)
{
qDebug()<<"close event pressed - ";
event->accept();
}