// main.cpp
MyApplication a(argc, argv);
MainWindow w;
QObject::connect(&a,
SIGNAL(activated
()), w.
getDialog(),
SLOT(show
()));
QObject::connect(&a,
SIGNAL(deactivated
()), w.
getDialog(),
SLOT(hide
()));
w.show();
// application class header
{
Q_OBJECT
public:
MyApplication(int argc, char **argv);
~MyApplication();
signals:
void activated();
void deactivated();
private:
};
// application class implementation
MyApplication
::MyApplication(int argc,
char **argv
): QApplication(argc, argv
){
installEventFilter(this);
}
{
if (event
->type
() == QEvent::ApplicationActivate) emit activated();
else if (event
->type
() == QEvent::ApplicationDeactivate) emit deactivated();
return false;
}
// main.cpp
MyApplication a(argc, argv);
MainWindow w;
QObject::connect(&a, SIGNAL(activated()), w.getDialog(), SLOT(show()));
QObject::connect(&a, SIGNAL(deactivated()), w.getDialog(), SLOT(hide()));
w.show();
// application class header
class MyApplication : public QApplication
{
Q_OBJECT
public:
MyApplication(int argc, char **argv);
~MyApplication();
signals:
void activated();
void deactivated();
private:
bool eventFilter(QObject *obj, QEvent *event);
};
// application class implementation
MyApplication::MyApplication(int argc, char **argv): QApplication(argc, argv)
{
installEventFilter(this);
}
bool MyApplication::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ApplicationActivate)
emit activated();
else if (event->type() == QEvent::ApplicationDeactivate)
emit deactivated();
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks