PDA

View Full Version : Problem with QProgressDialog



anoraxis
11th May 2011, 15:28
I'm using a QProgressDialog with the limits (0, 0) to show something during a sqlite query and preparing the results to show. The QProgressDialog window stays in blank all the time, not matter if the process took 1 second or minute. My code is something like:





QProgressDialog dialog(this);
dialog.setLabelText("Updating");
dialog.setMinimun(0)
dialog.setMaximum(0);
dialog.show();
try
{
// here I call a function that executes a sql query to a sqlite database and then updates the whole interface with the result.
dialog.accept();
}
catch (QString e)
{
QMessageBox::critical(this, "Error - " + qApp->applicationName(), e);
qApp->exit(1);
}

Reading other post I have seen that in cases of a long during process is better to use another thread instead of the main one. It's this correct? Can I block the program during the process so the user can't interact with it when using another thread?

wysota
11th May 2011, 16:29
Sql query blocks your application so that the progress bar doesn't have a chance to update itself. You can experiment with executing the query in a thread.

mvuori
11th May 2011, 16:42
As far as I understand, at least the title should appear before going into the blocking part.

Perhaps the UI operations are cached and need some extra help. I have sometimes added a xxxxx.update() after a xxxxx.show() to make a widget visible.

wysota
11th May 2011, 16:45
As far as I understand, at least the title should appear before going into the blocking part.
No. For the window to appear, events need to be processed.

Lesiok
12th May 2011, 09:18
As far as I understand, at least the title should appear before going into the blocking part.

Perhaps the UI operations are cached and need some extra help. I have sometimes added a xxxxx.update() after a xxxxx.show() to make a widget visible.

After widget show add QCoreApplication::processEvents. But the best solution is to move SQL operations to another thread.

anoraxis
12th May 2011, 14:28
Ok, thanks. I will the sql part to another thread.

Another thing, in my case the title of the QProgressDialog is the only element that appears, the rest of the dialog is blank.