Two Laptop Bag*
The moose likes C / C++ and the fly likes Possibility of running GUI on multithreads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Possibility of running GUI on multithreads" Watch "Possibility of running GUI on multithreads" New topic
Author

Possibility of running GUI on multithreads

Rekha Pai
Ranch Hand

Joined: Oct 30, 2008
Posts: 35
Hi,

Very glad to hear about this book.

I used C++ with QT gui and C with tcl/tk gui. At both places I

came across a problem of updating and refreshing the front end

(gui) for some event at the back end. This was because the gui runs

on single thread. Somehow I managed to update by writing into a hidden

widget which automatically calls the paint() method.

My question is can the gui run on multi thread?

Regards,
Rekha.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
Are QT and tcl/tk threadsafe?
Anthony Aj Williams
author
Ranch Hand

Joined: Jun 10, 2011
Posts: 56
Rekha Pai wrote:I used C++ with QT gui and C with tcl/tk gui. At both places I
came across a problem of updating and refreshing the front end
(gui) for some event at the back end. This was because the gui runs
on single thread. Somehow I managed to update by writing into a hidden
widget which automatically calls the paint() method.
My question is can the gui run on multi thread?


With many GUI frameworks (and I think QT is one of them) the GUI works best if all GUI changes happen on the same thread. This is often a requirement of the OS --- e.g. some Microsoft Windows API calls require that the thread calling the API is the thread that created the window.

A useful technique in this case is to use some kind of message queue to pass the data from the thread doing the work over to the GUI thread. This is covered in chapter 8.


Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/
just::thread C++11 thread library http://www.stdthread.co.uk
Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
Rekha Pai
Ranch Hand

Joined: Oct 30, 2008
Posts: 35
Campbell Ritchie wrote:Are QT and tcl/tk threadsafe?


Qt provides thread support in the form of platform-independent threading classes, a thread-safe way of posting events, and signal-slot connections across threads. This makes it easy to develop portable multithreaded Qt applications and take advantage of multiprocessor machines. Multithreaded programming is also a useful paradigm for performing time-consuming operations without freezing the user interface of an application.

Earlier versions of Qt offered an option to build the library without thread support. Since Qt 4.0, threads are always enabled.

tcl is thread safe but tk is not.

Regards,
Rekha.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possibility of running GUI on multithreads
 
Similar Threads
SWT Thread problem
Threads execution is disorder
Threads - join()
Question in thread
Help with GUI assignment.