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. How to check if the application has been minimized
Forum Updated to NodeBB v4.3 + New Features

How to check if the application has been minimized

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 984 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by
    #1
    int main(int argc, char *argv[])
    {
        QApplication application(argc, argv);
        Renderer w(model ); // This is  QWidget
        w.show();
        QObject::connect(&w, &QWindow::windowStateChanged, [&](Qt::WindowState state) {
            });
    
            // how will i define the QObject::connect 
        return application.exec();
    }
    
    What would be the parameters for the QObject::connect function ?
    
    jsulmJ 1 Reply Last reply
    0
    • S summit
      int main(int argc, char *argv[])
      {
          QApplication application(argc, argv);
          Renderer w(model ); // This is  QWidget
          w.show();
          QObject::connect(&w, &QWindow::windowStateChanged, [&](Qt::WindowState state) {
              });
      
              // how will i define the QObject::connect 
          return application.exec();
      }
      
      What would be the parameters for the QObject::connect function ?
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @summit said in How to check if the application has been minimized:

      What would be the parameters for the QObject::connect function ?

      You already have the connect, so what is the question?
      Just check state == Qt::WindowMinimized in your lambda...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        summit
        wrote on last edited by
        #3

        @jsulm No this does not connect it gives an error during compile time , no instance of overloaded function matches the argument list.

        so i try this

        QWindow *wndQT = (QWindow*)w.window();
        		QObject::connect(wndQT, &QWindow::windowStateChanged , [&](Qt::WindowState state) {
        			qDebug() << "Minimized";
        		});
        
        This is able to compile but the lambda is never executed.
        
        jsulmJ 1 Reply Last reply
        0
        • S summit

          @jsulm No this does not connect it gives an error during compile time , no instance of overloaded function matches the argument list.

          so i try this

          QWindow *wndQT = (QWindow*)w.window();
          		QObject::connect(wndQT, &QWindow::windowStateChanged , [&](Qt::WindowState state) {
          			qDebug() << "Minimized";
          		});
          
          This is able to compile but the lambda is never executed.
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @summit w.window() returns a QWidget, not QWindow.
          Try

          QObject::connect(QApplication::activeWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
          			qDebug() << "Minimized";
          		});
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @summit w.window() returns a QWidget, not QWindow.
            Try

            QObject::connect(QApplication::activeWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
            			qDebug() << "Minimized";
            		});
            
            S Offline
            S Offline
            summit
            wrote on last edited by
            #5

            @jsulm This does not compile as QApplication::activeWindow() also returns QWidget*

            i have to cast it to compile.

            QObject::connect((QWindow*)QApplication::activeWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
            qDebug() << "Minimized";
            });

            But still lambda does not execute.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              summit
              wrote on last edited by
              #6

              Using QApplication::focusWindow() i was able to get the window.

              QObject::connect(QApplication::focusWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
              qDebug() << "Minimized";
              });

              JonBJ 1 Reply Last reply
              1
              • S summit

                Using QApplication::focusWindow() i was able to get the window.

                QObject::connect(QApplication::focusWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
                qDebug() << "Minimized";
                });

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @summit
                Just for the record, you do actually need/ought check the value of the state parameter to the lambda:

                if (state == Qt::WindowMinimized) qDebug() << "Minimized";
                

                ?

                S 1 Reply Last reply
                1
                • JonBJ JonB

                  @summit
                  Just for the record, you do actually need/ought check the value of the state parameter to the lambda:

                  if (state == Qt::WindowMinimized) qDebug() << "Minimized";
                  

                  ?

                  S Offline
                  S Offline
                  summit
                  wrote on last edited by
                  #8

                  @JonB Yes i am doing that.

                  1 Reply Last reply
                  0

                  • Login

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