*Moderate dig*

The problem with calling deleteLater() on the QDialog or deleting it after exec() is, that for a short moment the dialog will freeze and then disappear when clicking a button that causes the function to return, instead of just disappearing normally (or fade-away animation under Vista/W7). That simply is not nice.

I have made a dirty workaround which does not take the lag from the main event loop, but at least lets the animation play smoothly:

dialogdestroyer.h:
Qt Code:
  1. #ifndef DIALOGDESTROYER_H
  2. #define DIALOGDESTROYER_H
  3.  
  4. #include <QThread>
  5. #include <QDialog>
  6.  
  7. class DialogDestroyer : public QThread
  8. {
  9. public:
  10. DialogDestroyer();
  11.  
  12. void DelayedDestruction(QDialog* lDialog);
  13.  
  14. private:
  15. void run();
  16.  
  17. QDialog* mDialog;
  18. };
  19.  
  20. #endif // DIALOGDESTROYER_H
To copy to clipboard, switch view to plain text mode 

dialogdestroyer.cpp:
Qt Code:
  1. #include <QTimer>
  2.  
  3. #include "dialogdestroyer.h"
  4.  
  5.  
  6. DialogDestroyer::DialogDestroyer() {
  7.  
  8. }
  9.  
  10. void DialogDestroyer::DelayedDestruction(QDialog* lDialog) {
  11.  
  12. mDialog = lDialog;
  13.  
  14. this->start();
  15.  
  16. }
  17.  
  18. void DialogDestroyer::run() {
  19.  
  20. msleep(300);
  21.  
  22. mDialog->deleteLater();
  23. this->deleteLater();
  24. }
To copy to clipboard, switch view to plain text mode 

Somewhere:
Qt Code:
  1. void MainWindow::on_actionOpen_triggered() {
  2.  
  3. QFileDialog* lDiag = new QFileDialog(this, QString("Select file to open"),
  4. QString("D:\\"), QString("Text files (*.txt)"));
  5.  
  6. int lResult = lDiag->exec();
  7.  
  8. if(lResult != QDialog::Rejected) {
  9. // Do stuff...
  10. }
  11.  
  12. (new DialogDestroyer())->DelayedDestruction(lDiag);
  13. }
To copy to clipboard, switch view to plain text mode 

There should be a better way/implementation, in my honest opinion.