If the applications really are friendly, i.e. both are under one's control, an easier solution might make use of a communication socket or shared library that allows to have the other application bring up itself.
Which seems to be tricky enough -- delay the call:
QTimer::singleShot( 2000,
this,
SLOT( toForeground() )
);
to this slot:
void MainWindow::toForeground()
{
qDebug() << SetForegroundWindow( this->winId() );
}
This will show the Task Bar and highlight the application icon shortly. It does not switch to the application.
Qt's own activateWindow()
results in a more persistent blinking task bar icon but does not raise the application.
This has been tried before:
The latter suggests:
showNormal();
raise();
activateWindow();
but that does not work for me on Windows 7 64 bit with Qt 4.8.1 and MSVC++ 2010.
Here is code that I think is also mentioned in the other questions:
The author writes
It always brings the window to the front, but the focus is somewhere
in the system :-( In some other app…
This I can confirm.
Edit:
Windows' behaviour can (shouldn't!?) be changed globally via Registry:
https://stackoverflow.com/a/6087923/1619432 points to
http://qt-project.org/faq/answer/qwidget_activatewindow_-_behavior_under_windows