Hi All,
The issue i am facing is basically how do i detect my application has lost focus as a result of user doing something else maybe checking there SMS or making/receiving a call.
All i want to do is detect this focus change and 'Pause' my app from doing any heavy calculation or simply sending a message "User Inactive State" to TCP Server.
Regards,
Javed
Added after 25 minutes:
i have tried these two solutions but none works for me, perhaps i am doing it wrong.
Solution 1:- Does not ssems to be emitting signal when app looses focus.
ProgressWin
::ProgressWin(QWidget *parent
) : QDialog(parent
), ui
(new Ui
::ProgressWin){
ui->setupUi(this);
#ifdef Q_OS_SYMBIAN
this->showMaximized();
#else
this->show();
#endif
QWidget::setFocusPolicy(Qt
::StrongFocus);
}
{
if(NULL == old)
{
// do something or nothing
}
else if(NULL == now)
{
Pause(); // Pause all calculation
SendTCP_UserInActive();
}
else
{
// do something or nothing
}
}
ProgressWin::ProgressWin(QWidget *parent) : QDialog(parent), ui(new Ui::ProgressWin)
{
ui->setupUi(this);
#ifdef Q_OS_SYMBIAN
this->showMaximized();
#else
this->show();
#endif
QWidget::setFocusPolicy(Qt::StrongFocus);
connect(this, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(OnAppFocusChanged(QWidget*, QWidget*)));
}
void ProgressWin::OnAppFocusChanged(QWidget* old, QWidget* now)
{
if(NULL == old)
{
// do something or nothing
}
else if(NULL == now)
{
Pause(); // Pause all calculation
SendTCP_UserInActive();
}
else
{
// do something or nothing
}
}
To copy to clipboard, switch view to plain text mode
Solution 2 :- Does not work if user selects "Calendar key or Email Key" pressed on Nokia E52 Handset. Its a crappy solution anyway.
void ProgressWin
::keyPressEvent(QKeyEvent *e
) {
switch (e->key())
{
case Qt::Key_Calendar:
case Qt::Key_LaunchMail:
case Qt::Key_Menu:
.........
.........
.........
Pause(); // Pause all calculation
SendTCP_UserInActive();
break;
default:
// do something or nothing
}
}
void ProgressWin::keyPressEvent(QKeyEvent *e)
{
switch (e->key())
{
case Qt::Key_Calendar:
case Qt::Key_LaunchMail:
case Qt::Key_Menu:
.........
.........
.........
Pause(); // Pause all calculation
SendTCP_UserInActive();
break;
default:
// do something or nothing
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks