views:

134

answers:

3

I have a form in which I want to periodically refresh its values(mostly labels but 2 comboboxes and 1 spinboxe). I have done this before with a QThread but this time I would like to do it with a QTimer. Would that be ok or would it potentially create problems like freezing the GUI. There are a couple of fields in the form that are both user editable and periodically refreshed.

UPDATE: im removing the QTimer because it is causing problems.

+2  A: 

I don't think that refreshing from GUI would make any difference against refreshing from a QThread - the controls painting takes place in the GUI (=main) thread anyway. If your values don't require a lot of calculations before being set, you can safely do this from GUI thread.

The only thing to watch for is to not refresh the particular value if user is currently editing it - I guess that would make a real surprise for him :) Unless you have some special ui design of course...

dpimka
A: 

I've done this in the GUI thread and haven't encountered any problems. What I needed it for was to update a timer for a popup (it displayed something like "Reconnecting in [time] seconds" and I was updating the [time] when the timer fired)

You must be careful not to do any CPU intensive computation though (ie don't compute some Mandlebrot values in the GUI thread or something of the sort) - that will freeze the GUI thread.

laura
if the computations are long though you can still call QApplication::processEvents() regularly to prevent freezing.
yan bellavance
but know that this is a last thing you'd want to do :)even Qt developers often repeat: "do not use processEvents. ever."
dpimka
A: 

if all you do is refresh the form you should be okay but if you call long function that require calls to QCoreApplication::processEvents(); then you shouldn't. I tried using the timer and I had problems which went away as soon as I removed the timer and used a thread in which I emited a signal to the main thread to refresh the form once the work was done.

yan bellavance