Install an event filter to detect QEvent::Close, e.g.

Qt Code:
  1. #include <QtGui>
  2.  
  3. class EventSignaller : public QObject
  4. {
  5. Q_OBJECT
  6.  
  7. signals:
  8. void closing();
  9.  
  10. protected:
  11. bool eventFilter(QObject *object, QEvent *event)
  12. {
  13. if(event->type() == QEvent::Close)
  14. emit(closing());
  15.  
  16. return QObject::eventFilter(object, event);
  17. }
  18. };
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22. QApplication app(argc, argv);
  23.  
  24. QWidget w1;
  25. w1.setWindowTitle("w1");
  26. w1.show();
  27.  
  28. QWidget w2;
  29. w2.setWindowTitle("w2");
  30. w2.show();
  31.  
  32. EventSignaller s;
  33. w1.installEventFilter(&s);
  34. w2.connect(&s, SIGNAL(closing()), SLOT(close()));
  35.  
  36. return app.exec();
  37. }
  38.  
  39. #include "main.moc"
To copy to clipboard, switch view to plain text mode