[SOLVED] Bring to front window application managed with QProcess
-
wrote on 29 Jul 2013, 07:58 last edited by
Hello, I'm developing a Qt desktop app. This app executes another external app (assistant) managed with QProcess. But when I push the button that shows the assistant, that window does not appear in front of the mainwindow.
I've tryed with:- In mainwindow.h:
@public slots:
void on_actionAssistant_triggered();private:
QProcess assistantProcess;@- In mainwindow.cpp:
@void MainWindow::on_actionAssistant_triggered()
{
if(!assistantProcess.isOpen())
{
const QStringList args = getAssistantProcessArguments();assistantProcess.start(QLatin1String("assistant"), args); if (!assistantProcess.waitForStarted()) { return; } } QByteArray byteArray; byteArray.append("show contents;"); assistantProcess.write(byteArray); ...@
But it does not work. Any suggestion?
Thanks in advance. -
wrote on 29 Jul 2013, 11:19 last edited by
Hi Bonride
use this flag in mainwindow
setWindowFlags(windowFlags()|Qt::WindowStaysOnBottomHint);or
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
in external app -
wrote on 29 Jul 2013, 15:14 last edited by
I don't think he want's the new process' window to permanently stay or on top, nor his "main" process' window to permanently stay on bottom.
--
I'd rather do:
@unsigned long childPID= assistantProcess.pid()->dwProcessId;
EnumWindows(focusChildProcWindow, reinterpret_cast<LPARAM>(&childPID));@Using a callback function like this:
@static BOOL CALLBACK focusChildProcWindow(HWND hwnd, LPARAM lParam)
{
DWORD processId = reinterpret_cast<WORD>(lParam);
DWORD windowProcessId = NULL;
GetWindowThreadProcessId(hwnd, &windowProcessId);
if(windowProcessId == processId)
{
SwitchToThisWindow(hwnd, TRUE);
SetForegroundWindow(hwnd);
return FALSE;
}return TRUE;
}@This will enumerate all windows and bring the desired window (the window belonging to your child process) to the front.
-
wrote on 30 Jul 2013, 15:57 last edited by
Thank you both for answering, I really needed is what has answered MuldeR, but I get an error. Do not quite understand the code so i do not understand the error. I put the error text below (the first two are warning):
In function 'BOOL focusChildProcWindow(HWND, LPARAM)':
warning: converting to non-pointer type 'DWORD {aka long unsigned int}' from NULL [-Wconversion-null]At global scope:
warning: 'BOOL focusChildProcWindow(HWND, LPARAM)' defined but not used [-Wunused-function]In function
ZN10MainWindow34on_actionNeuralAssistant_triggeredEv':* error: undefined reference to
MainWindow::focusChildProcWindow(HWND__, long)@8'
ld returned 1 exit statusThis is what I've done:
In mainwindow.h:
@static BOOL CALLBACK focusChildProcWindow(HWND hwnd, LPARAM lParam);@In mainwindow.cpp:
@static BOOL CALLBACK focusChildProcWindow(HWND hwnd, LPARAM lParam)
{
DWORD processId = reinterpret_cast<WORD>(lParam);
DWORD windowProcessId = NULL;
GetWindowThreadProcessId(hwnd, &windowProcessId);
if(windowProcessId == processId)
{
SwitchToThisWindow(hwnd, TRUE);
SetForegroundWindow(hwnd);
return FALSE;
}return TRUE;
}void MainWindow::on_actionNeuralAssistant_triggered()
{
unsigned long childPID= assistantProcess.pid()->dwProcessId;EnumWindows(focusChildProcWindow, reinterpret_cast<LPARAM>(&childPID));
...
}@Regards
-
wrote on 30 Jul 2013, 16:04 last edited by
-
Remove function declaration of focusChildProcWindow() from your .h file. You only need that function in the same .cpp file where the function is defined, so no need to add a forward declaration to the "public" header file.
-
You can ignore the type-cast warning for now ;)
-
Not quite sure about the linker error, but probably will go away when you fix the first issue.
-
-
wrote on 30 Jul 2013, 16:42 last edited by
It works!
Thank you very much MuldeR.
3/6