Results 1 to 5 of 5

Thread: How to detect whether a Qt application is running in foreground or background ?

  1. #1
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default How to detect whether a Qt application is running in foreground or background ?

    Does Qt application/ mainwindow or some other class provides an API to to detect whether a Qt application is running in foreground or background ?

    Or is there some kind of signal/ slot mechanism for the same. Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect whether a Qt application is running in foreground or background ?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to detect whether a Qt application is running in foreground or background ?

    Thanks wysota.. I actually want a Signal mechanism.
    As in when some other application comes in foreground, i receive a signal in my running application and in the corresponding slot I can perform some action.

    the above API's you mentioned can be used when I specifically want to check the status of my application.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to detect whether a Qt application is running in foreground or background ?

    You asked for an API, you got an API. If you want a signal, ask for a signal

    A suitable signal might be QApplication::focusChanged.

  5. #5
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to detect whether a Qt application is running in foreground or background ?

    Ya I should have framed the question in a better way
    Thanks I will try using this signal in my app


    Added after 1 56 minutes:


    I was able to do this using the QApplication::focusChanged signal, doing a connect. corresponding slot:

    void CApplication::OnAppFocusChanged(QWidget* old, QWidget* now)
    {
    int i = 0;
    if(NULL == old)
    {
    //Focus regained..This is foreground app now
    i=1;
    }
    else if(NULL == now)
    {
    //Focus lost. This is background app now.
    i = 2;
    }

    }
    Last edited by abk883; 11th January 2011 at 07:56.

  6. The following user says thank you to abk883 for this useful post:

    swdev (5th July 2014)

Similar Threads

  1. how to detect if the NIC is up and running
    By sky in forum General Programming
    Replies: 0
    Last Post: 21st December 2010, 09:52
  2. Replies: 9
    Last Post: 14th September 2010, 18:00
  3. Receiving application foreground event
    By kokilakr in forum Qt Programming
    Replies: 0
    Last Post: 24th June 2010, 11:31
  4. How to detect a running application
    By yogesh in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2009, 10:22
  5. Replies: 5
    Last Post: 9th June 2008, 11:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.