Reputation: 11780
I would like to be notified when the user switch to another application so I use the installEventFilter method to catch the events:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *sender, QEvent *event)
{
qDebug() << event->type();
return QMainWindow::eventFilter(sender, event);
}
When I switch to another application I get the following events:
Shouldn't I receive ApplicationDeactivate (which seems to be deprecated) or ApplicationStateChange when I switch to another application?
I'm under MacOS and test with the following Qt versions: 5.1.1, 5.2.0, 5.2.1.
Upvotes: 1
Views: 705
Reputation: 98435
You should connect to the QGuiApplication::applicationStateChanged
signal. If it doesn't fire, that's a bug and should be reported. I don't think you do that, though.
The ApplicationStateChange
event is used internally by Qt, you're not supposed to worry about it. It is likely sent to the application instance. Also, all of this is for Qt 5.2.x. For 5.1 and earlier, things are different.
Upvotes: 1