Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Re-activate (known as create a new substance) a QMainWindow after the last QMainWindow is closed
QtWS25 Last Chance

Re-activate (known as create a new substance) a QMainWindow after the last QMainWindow is closed

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmainwindowqapplicationqguiapplicationreshownsubclass
3 Posts 3 Posters 416 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JackMyson
    wrote on last edited by
    #1

    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.

    SGaistS 1 Reply Last reply
    0
    • J JackMyson

      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.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Based on this feature request, you should be able to react on the ˋQEvent::ApplicationActivate`.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Based on this feature request, you should be able to react on the ˋQEvent::ApplicationActivate`.

        M Offline
        M Offline
        mpergand
        wrote on last edited by mpergand
        #3

        @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.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved