[Interest] "Loading", recursion and GUI's

R. Reucher rene.reucher at batcom-it.net
Tue Jan 8 09:28:04 CET 2013


On Tuesday 08 January 2013 09:15:50 William Hallatt wrote:
> I have to update the tree widget with each element visited and as far as
> I'm aware, one cannot use widget classes in separate threads (QThread).
> You are probably right that I can do that via a signals and slots (thanks
> for that, I don't know why I didn't think of it, it's rather obvious), but
> won't that "cost" roughly the same?  Each time the recursive function is
> called, a signal will be emitted telling the GUI to update so how will it
> be different?
Well, the major difference is that you're not "blocking" the main thread aka 
GUI thread, so it has time for GUI updates.

However, as others already stated, in your specific case a simple

qApp->processEvents();

*before* starting the recursion should actually be sufficient. And if you want 
your GUI to be responsive while the recursion runs, you should periodically 
call it again. However, this method will most likely be slower than the 
threaded approach, though much simpler to implement.

HTH, René



More information about the Interest mailing list