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
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
Did you try checking QWidget::isVisible(), QWidget::isMinimized() and QWidget::isActive()?
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.
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.
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.
swdev (5th July 2014)
Bookmarks