PDA

View Full Version : Want to quit application if any window is closed



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();
}

anda_skoa
11th May 2016, 09:43
You could probably use a global event filter, check for close events on windows, and call QApplication::quit() in a delayed fashion when you encounter them.

Cheers,
_