PDA

View Full Version : Update GUI in a thread



olivier1978
8th January 2011, 20:20
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

wysota
8th January 2011, 20:47
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).

olivier1978
8th January 2011, 21:01
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 (http://www.qtcentre.org/threads/14814-How-to-keep-the-GUI-responsive)?

Best regards,

Olivier

wysota
8th January 2011, 22:33
Here is an article that covers some relevant things in details: Keeping the GUI Responsive.