View Full Version : How to detect whether a Qt application is running in foreground or background ?
abk883
10th January 2011, 18:15
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
wysota
10th January 2011, 18:23
Did you try checking QWidget::isVisible(), QWidget::isMinimized() and QWidget::isActive()?
abk883
10th January 2011, 19:50
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.
squidge
10th January 2011, 20:09
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.
abk883
11th January 2011, 08:56
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;
}
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.