PDA

View Full Version : how to force widgets update



Onanymous
14th June 2010, 16:19
Hi, the following code


statusLabel = new QLabel(" idle ", this);
statusBar()->addWidget(statusLabel);

statusLabel->setText("doing something");
myobject->do_smth_for_minute();
statusLabel->setText("something done");

does not update the statusLabel, it just stays "something done". How can I force updating the widget?

high_flyer
14th June 2010, 16:28
try calling update();

wysota
14th June 2010, 17:15
You are blocking the event loop so the widget can't update itself. Read this article: Keeping the GUI Responsive.

Onanymous
14th June 2010, 17:23
update() does not work (on windows at least). That is the point, I am afraid I need to put a task to a thread, but that just is not right, I do not need it to be responsive in between two updates of the widget, I only want to update it once before and once afterwards.

MorrisLiang
14th June 2010, 17:35
an easy way, set a QTimer which will timeout in a few millisec,connect its timeout SIGNAL

wysota
14th June 2010, 17:37
See the part of the article that deals with manually triggering event processing.

@MorrisLiang: I'm afraid this won't work as event loop is blocked so timers don't fire. update() is called, it just doesn't cause the desired effect.