Chris
Chris

Reputation: 1283

refresh/update GUI during slot running

All attributes of GUI elements (text, items ...) are updated after the slot have finished running, and I have a little label that displays the status of the application (i.e. "Refreshing ...", "Configuring ...", "Scanning ...", "Done", etc) during a triggered slot is running.

How can I set a label's text to something like "Refreshing ..." immediately after a slot was triggered, and when slot is almost done change label's text to something like "Done"?

Currently I'm doing this by issuing

    ui->Status->setText("Refreshing ...");
    ...
    ui->Status->setText("Done");

inside the slot, but the change is visible only after the slot is done, so I never get to see "Refreshing ...".

Sorry if this is something easy, but I'm new to OOP and I keep thinking sequentially.

Upvotes: 2

Views: 4537

Answers (1)

Chris
Chris

Reputation: 1283

This is what I ended up doing back then. "qApp->processEvents();" was the key. Repaint() is not enough.

void Widget::SetStatus(QString status)
{
   ui->Status->setText(status);
   ui->Status->repaint();
   qApp->processEvents();
}

Upvotes: 2

Related Questions