Results 1 to 2 of 2

Thread: Want to quit application if any window is closed

  1. #1
    Join Date
    Jan 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Want to quit application if any window is closed

    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.

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. QPushButton *button = new QPushButton(this);
    5. button->setText("close");
    6.  
    7. connect(button, SIGNAL(clicked(bool)), this, SLOT(dialogbox()));
    8. connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(quitMyApp()));
    9. }
    10.  
    11. void MainWindow :: dialogbox()
    12. {
    13.  
    14. dialog = new QDialog(this);
    15. dialog->setWindowTitle("button");
    16. dialog->setGeometry(150,150,350,350);
    17. dialog->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
    18. dialog->show();
    19.  
    20. //QCloseEvent *eve = new QCloseEvent;
    21.  
    22. //dialog->closeEvent(eve);
    23. }
    24.  
    25. void MainWindow :: quitMyApp()
    26. {
    27. qDebug()<<"quit the child window";
    28. }
    29.  
    30. void MainWindow :: childEvent(QChildEvent *eve)
    31. {
    32. // qDebug()<<"child event";
    33. }
    34.  
    35. void MainWindow :: closeEvent(QCloseEvent *event)
    36. {
    37. qDebug()<<"close event pressed - ";
    38. event->accept();
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 11th May 2016 at 08:39. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Want to quit application if any window is closed

    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,
    _

Similar Threads

  1. Way to detect if a window is hidden/closed
    By fgoset in forum Qt Quick
    Replies: 2
    Last Post: 5th December 2015, 11:40
  2. Replies: 10
    Last Post: 6th August 2012, 00:46
  3. Why my application quit?
    By yxtx1984 in forum Newbie
    Replies: 1
    Last Post: 7th February 2010, 05:46
  4. Replies: 11
    Last Post: 4th June 2008, 07:22
  5. [SOLVED] detecting when a mdi window is closed
    By elcuco in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2006, 20:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.