Results 1 to 4 of 4

Thread: gui and fork()

  1. #1
    Join Date
    Jan 2008
    Posts
    4

    Default gui and fork()

    Hello!

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

    Qt Code:
    1. void Form1::pq_listening() {
    2. pid_t ppid;
    3. ppid=fork();
    4.  
    5. switch (ppid)
    6.  
    7. { case -1:
    8. ui.textEdit->append("error"); break;
    9.  
    10. case 0:
    11. ui.textEdit->append("fork"); break;
    12.  
    13.  
    14. default:
    15. ui.textEdit->append("parent"); break;
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: gui and fork()

    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.

  3. #3
    Join Date
    Jan 2008
    Posts
    4

    Default Re: gui and fork()

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: gui and fork()

    The safest way will be to create the GUI after you fork the process or to write two separate applications.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.