Re-activate (known as create a new substance) a QMainWindow after the last QMainWindow is closed
-
As mentioned in the topic title, I have the following code.
(Note: The subclassed MainWindow and its widgets will not be shown because of the space.)main.cpp
#include <QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); #ifdef Q_OS_DARWIN app.setQuitOnLastWindowClosed(false); #endif MainWindow mw; mw.show(); app.exec(); }
Running in macOS (I haven't built or decided to run in iOS so its fine), the application has really had a small gray dot representing the application is on work at that time; however, differ to the complex and native apps, my Qt app won't react to mouse-clicking on its icon under the dock and re-show a new MainWindow substance.
My question is, is there a public method that allows app react to icon-clicking by the users with re-create functionality enabled, in pure Qt C++ code? Thanks for reply.
-
Hi,
Based on this feature request, you should be able to react on the ˋQEvent::ApplicationActivate`.
-
@SGaist said in Re-activate (known as create a new substance) a QMainWindow after the last QMainWindow is closed:
Based on this feature request, you should be able to react on the ˋQEvent::ApplicationActivate`.
I'm using that in a subclass of QApplication.
The idea in pseudo code:void Application::applicationStateChanged ( Qt::ApplicationState state) { if(state==Qt::ApplicationActive AND no window is open AND OpenUntitledWindow ) { openNewWindow(); }
OpenUntitledWindow is a flag setting if an new window/document should be opened on startup, it works also when the app is reactivated with the code above.