Results 1 to 4 of 4

Thread: Update GUI in a thread

  1. #1
    Join Date
    Jan 2011
    Location
    Paris
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Update GUI in a thread

    Hi all,

    Searching the web and the forum, I did not found any answer to my question. I am building an app which has tu run either in console mode (without Qt) or in GUI mode (with Qt of course). Since some of the processes are time consuming, the GUI is blocked if I do not use a thread. However, I need to do some logs, in the standard output in console mode, and in a QTextBrowser in GUI mode.

    I use boost thread.

    The solutions I found on the forum all use a mechanism of Qt signals / slots. Since I do not use Qt in my console application, how van I handle that?

    Hope you could help.

    Best regards

    Olivier

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI in a thread

    The most proper solution would be to have #ifdef blocks in your code (or even two different files) that would implement the two different cases. Then you'd need to rebuild your program once for use with a GUI and once without it. An alternative is to run implement the GUI in such a way that it is a simple program that only displays a couple things and it runs the real (console mode) program as a separate process (through QProcess) and talks to it. Your console mode program could have a switch that allows to set it into GUI-slave or standalone mode (and it would cause it to output data differently if needed).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2011
    Location
    Paris
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI in a thread

    Thank you wysota.

    I was wondering if I could avoid the #ifdef blocks solution. This is however probably the most simple one. So, is the way to process still the same as the one described in this thread?

    Best regards,

    Olivier
    Last edited by olivier1978; 8th January 2011 at 20:32.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI in a thread

    Here is an article that covers some relevant things in details: [wiki]Keeping the GUI Responsive[/wiki].
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 29th September 2010, 17:44
  2. Update GUI from another thread
    By Anne in forum Qt Programming
    Replies: 9
    Last Post: 14th July 2010, 15:08
  3. update a wigdet in a thread is no allow?
    By lanmanck in forum Qt Programming
    Replies: 8
    Last Post: 25th October 2009, 03:05
  4. Replies: 16
    Last Post: 7th October 2009, 08:17
  5. update widget from separate thread
    By method in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2009, 14:33

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.