Hi,
I am using QProcess for starting cmd.exe application with /c "FilePath" parameter. With cmd.exe i show file to user. But file opened behind the other windows and has no focus.
How can i set focus to opened file with QProcess?
Thanks
Printable View
Hi,
I am using QProcess for starting cmd.exe application with /c "FilePath" parameter. With cmd.exe i show file to user. But file opened behind the other windows and has no focus.
How can i set focus to opened file with QProcess?
Thanks
QProcess can't know that you have used it to open some kind of window, don't expect that it'll have an api related to specific applications.
I see two workarounds. First, easy and unreliable, is to call FindWindow winapi procedure, and use returned window handle to bring the window to the front with ShowWindow, so it'll look like:
Second, more reliable, is to enumerate all opened windows, for each of them check the process id of process which opened the window, and use pid() of the QProcess for comparison. If the window pid equals notepad QProcess pid, you can call ShowWindow, passing the window handle like above:Code:
HWND handle = FindWindow(0,windowTitle); // i'm not sure what will be the title, probably "Document.txt - Notepad" or something if( ShowWindow(handle,SW_SHOW) ){ qDebug() << "hurray"; }
1) EnumWindows - for "looping" through all opened windows (here you'll get HWND of window)
2) GetWindowThreadProcessId - for getting process id of window
3) PROCESS_INFORMATION structure - this you'll get with QProcess:: pid() (you want to use dwProcessId member)
4) ShowWindow - call it using HWND from 1) if pid from 2) equals pid from 3)
Simple, isn't it ?
Hello,
i'm trying to call a process and i'd like to set focus in this process.
My Source is:
QString program = "/opt/sygic/Drive/Maemo/drive -cwd=/home/user/MyDocs/Drive/Maemo -rfull";
QProcess *myProcess = new QProcess(this);
myProcess->start(program);
myProcess->waitForFinished();
... and what have you tried so far ?
I'm new Qt developer and i'd like to call a process in my QDialog form.
I have a button in this form that calls this SLOT when the button is pressed.
My goal is set the focus in this new process, but i can't to do it..
Now, i'm researching about Handle window, but i don't know if it is the solution for this issue.
Post #2 is about windows, what is your target platform ?
@down: Of course ;) sorry, I can't help you in that case, maybe someone else knows how to do that.
linux - maemo