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. App Icon notification behaviour with respect to focus-in and focus-out of the application
Forum Updated to NodeBB v4.3 + New Features

App Icon notification behaviour with respect to focus-in and focus-out of the application

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.6k Views 2 Watching
  • 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.
  • G gully

    @SGaist said in App Icon notification behaviour with respect to focus-in and focus-out of the application:

    QGuiApplication:: applicationStateChanged

    I am using QApplication, is it anyways possible with QApplication?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @gully
    Hi
    Since its
    class Q_WIDGETS_EXPORT QApplication : public QGuiApplication

    it should be possible ?

    1 Reply Last reply
    1
    • G Offline
      G Offline
      gully
      wrote on last edited by
      #5
      QApplication a(argc, argv);
          livewindow window;
      
          QApplication::connect(a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state)));
      
      

      This is what I am doing..but getting an error..What would be the right way to do this?

      mrjjM 1 Reply Last reply
      0
      • G gully
        QApplication a(argc, argv);
            livewindow window;
        
            QApplication::connect(a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state)));
        
        

        This is what I am doing..but getting an error..What would be the right way to do this?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @gully
        Well, first of all, always show the actual error :)
        in this case i think you need

        QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state))); // dont include varname, only type

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gully
          wrote on last edited by gully
          #7

          @mrjj said in App Icon notification behaviour with respect to focus-in and focus-out of the application:

          QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state)));

          Now I am getting

          error: no matching function for call to 'connect'
          QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState)),window, SLOT(appstate(Qt::ApplicationState)));
          ^~~~~~~~~~~~~~~~

          mrjjM 1 Reply Last reply
          0
          • G gully

            @mrjj said in App Icon notification behaviour with respect to focus-in and focus-out of the application:

            QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state)));

            Now I am getting

            error: no matching function for call to 'connect'
            QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState)),window, SLOT(appstate(Qt::ApplicationState)));
            ^~~~~~~~~~~~~~~~

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Hmm
            let me try
            is window , a normal MainWindow in main, or where do you do it ?

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #9

              Hi
              Tried.

              int main(int argc, char* argv[]) {
                QApplication a(argc, argv);
                MainWindow w;
                w.show();
                qDebug() << "works" << QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState)), &w, SLOT(appstate(Qt::ApplicationState)));
                return a.exec();
              }
              
              

              return true so seems to like it.

              in mainwindow , i have

              public slots:
                  void appstate(Qt::ApplicationState) {}
              

              update:
              i also put qDebug() in appstate
              and it fires/works.

              1 Reply Last reply
              1
              • G Offline
                G Offline
                gully
                wrote on last edited by
                #10

                Thanx a lot..yeeah its working now... But I wonder what I was doing wrong?

                mrjjM 1 Reply Last reply
                0
                • G gully

                  Thanx a lot..yeeah its working now... But I wonder what I was doing wrong?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #11

                  @gully
                  my best guess is you forgot & if the objects you connect is not pointers.
                  Like MainWindow in main.cpp.
                  so it was &window but not sure if pointer or not.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gully
                    wrote on last edited by
                    #12

                    Thanks a ton for pointing it out.Yes indeed that is what I missed out.

                    mrjjM 1 Reply Last reply
                    1
                    • G gully

                      Thanks a ton for pointing it out.Yes indeed that is what I missed out.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @gully
                      Just as a note.
                      Unless in main.cpp , if you need to use & for a connect, check that the object wont run out of
                      scope and be deleted when function ends.
                      In main.cpp, the "return a.exec();" blocks and it wont run out of scope.
                      But in other places, having to use & should raise a flag in head so check the objects in the
                      connect. (should be pointers in most places)

                      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