PDA

View Full Version : gui and fork()



msh
7th January 2008, 17:43
Hello!

I've got some problem with fork(). My code:



void Form1::pq_listening() {
pid_t ppid;
ppid=fork();

switch (ppid)

{ case -1:
ui.textEdit->append("error"); break;

case 0:
ui.textEdit->append("fork"); break;


default:
ui.textEdit->append("parent"); break;
}
}


after it, in textEdit I have only "parent". What should I do with it?

marcel
7th January 2008, 18:50
This doesn't work this way.
Qt widgets must be modified only by the GUI thread.

You can't have two processes acting on the same GUI. Actually, in your case I don;t even know what the behavior will be.

If you really want to experiment with threads, then I suggest QThread. If you want to modify widgets from other threads, don't! Instead use custom events or signals and slots.

msh
7th January 2008, 23:03
The program is a client application for messaging (using IPC queues).
Parent process is used for sending messages, child process for receiving.
The child process is listening on queue. When he gets some messages, it should show it in textEdit.
What would be the best solution for me?

jacek
7th January 2008, 23:08
The safest way will be to create the GUI after you fork the process or to write two separate applications.