diff --git a/src/app/main.cpp b/src/app/main.cpp
index f9b2cd747a09981bd875a5dba332c5b0d3e82672..a5c9606c87b9cd554eacb29e353804202cfbe801 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -505,6 +505,10 @@ int main(int argc, char **argv)
     QObject::connect(&app, SIGNAL(fileOpenRequest(QString)), coreplugin->plugin(),
                      SLOT(fileOpenRequest(QString)));
 
+    // quit when last window (relevant window, see WA_QuitOnClose) is closed
+    // this should actually be the default, but doesn't work in Qt 5
+    // QTBUG-31569
+    QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
     // shutdown plugin manager on the exit
     QObject::connect(&app, SIGNAL(aboutToQuit()), &pluginManager, SLOT(shutdown()));