C++ (Qt)#ifndef DIALOGCLOSER_H#define DIALOGCLOSER_H #include <QObject> class DialogCloser : public QObject{ Q_OBJECTpublic: explicit DialogCloser( QObject *parent = 0 ); signals: void finished(); public slots: void start();}; #endif // DIALOGCLOSER_H
C++ (Qt)#include "dialogcloser.h"#include <QApplication>#include <QWindow>#include <QCloseEvent> DialogCloser::DialogCloser( QObject *parent ) : QObject( parent ){} void DialogCloser::start(){ QWindow *wnd = QApplication::modalWindow(); if( wnd ) { QCloseEvent ev; QApplication::sendEvent( wnd, &ev ); QMetaObject::invokeMethod( this, "start", Qt::QueuedConnection ); } else { deleteLater(); emit finished(); }}
C++ (Qt)void ConnectManager::beginDeactivate(){ DialogCloser *cls = new DialogCloser; connect( cls, SIGNAL(finished()), SLOT(deactivate()) ); cls->start();}