If the applications are really friendly, i.e. both are under one control, a simpler solution can use a communication socket or a shared library, which allows you to get another application.
It seems to be quite difficult to delay the call:
QTimer::singleShot( 2000, this, SLOT( toForeground() ) );
in this slot:
void MainWindow::toForeground() { qDebug() << SetForegroundWindow( this->winId() ); }
This will display the taskbar and highlight the application icon as soon as possible. It does not switch to the application.
Qt's own activateWindow() results in a more stable blinking taskbar icon, but does not raise the application.
This has been verified previously:
The latter involves:
showNormal(); raise(); activateWindow();
but this does not work for me on a 64-bit version of Windows 7 with Qt 4.8.1 and MSVC ++ 2010.
Here is the code that I think is also mentioned in other issues:
The author writes
It always brings the window to the forefront, but the focus is somewhere in the system :-( In another application ...
I can confirm this.
<h / "> Edit: Windows behavior may (should not !?) change globally through the registry: fooobar.com/questions/472254 / ... points to http://qt-project.org/faq/answer/qwidget_activatewindow_- _behavior_under_windows
source share