PDA

View Full Version : How to activate another process?



gtthang
2nd February 2006, 09:22
I have the process A, it started the process B at begining of program using QProcess. And now, I want that when I click a button in the process A, the process B (running) will be activated immediately. Has any way to do that?
Thanks for reading.

zlatko
2nd February 2006, 09:49
If you start process B in begin of process A then what you mean under "activate"? Do you want send some data to process B?

gtthang
2nd February 2006, 10:24
I mean that the main window/dialog of the process B will be shown on top and receives the mouse/keyboard focus immediately.
Thanks very much.

high_flyer
2nd February 2006, 16:59
from the docs of QProcess (Qt4) it looks like it could be done with write() and read()...

yop
2nd February 2006, 21:40
from the docs of QProcess (Qt4) it looks like it could be done with write() and read()...That should trigger a call to
void QWidget::activateWindow ()

Something like:


Process A starts Process B
Process receives the button clicked signal and writes a message to Process B stdin
Process B calls void QWidget::activateWindow() for the widow/widget you want to receive keyboard focus

gtthang
3rd February 2006, 05:07
Thanks everyone, but I still have some questions.

To yop:
- Where should I call to QWidget::activeWindow() in code of the process B?
- How can the process B know that the process A has just written a message to it?

I really want the process B is controlled by A. (The process A needs to show some dialogs of B like its dialogs). I intend to use a shared memory between 2 processes. When the process A wants to force B into doing something, it'll writes the messages/commands into the shared memory. The process B'll have a thread checks this shared memory continuously to receive the messages from the process A and will show the corresponding dialogs. But I think that the dialogs of the process B will not show on top to receive keyboard focus as I expect.

yop
3rd February 2006, 08:53
- Where should I call to QWidget::activeWindow() in code of the process B?Just realized you're using windows:
On Windows, if you are calling this when the application is not currently the active one then it will not make it the active window. It will change the color of the task bar entry to indicate that the window has changed in some way. This is because Microsoft do not allow an application to interrupt what the user is currently doing in another application.Sorry, blaim Bill ;)
To answer your question, when process B is triggered it should be called from the widget you want shown.
- How can the process B know that the process A has just written a message to it?
Use stdin or a socket.