There was recently a bug, which happened when closing most of QtD apps, more complicated than Hello world. Consider the following example:
int main(char[][] args) { auto app = new QApplication(args); auto mainWin = new MainWindow; mainWin.show; return app.exec; }
where MainWindow? is our custom QMainWindow subclass, containing toolbars, menus, etc. Once we go out of main() scope GC performs a collection. The problem is that the order, in which CG finalizes objects is not defined and, in our example, it happens to call mainWin's destructor after app's destructor has been called. Qt requires that all GUI-related objects be destroyed before the instance of QApplication is destroyed. The requirement is not met and the application crashes. One possible way to enforce object destruction order is to use 'scope' storage class, which allocates objects on stack, constructs them in lexical order and destroys in the reverse order:
int main(char[][] args) { scope app = new QApplication(args); scope mainWin = new MainWindow; mainWin.show; return app.exec; }
