Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QProgressDialog: problems about MinimumDuration

I'm using QT 4.8.5. I met some problems on QProgressDialog with MinimumDuration. Here is the documentation: http://doc.qt.io/qt-4.8/qprogressdialog.html#minimumDuration-prop.

1.Test with the following code. The dialog is not displayed at all. But the documentation says: "the dialog will pop up after the minimumDuration time or as soon as any progress is set".

QProgressDialog* dlg = new QProgressDialog("Test", "cancel", 0, 10);
dlg->setMinimumDuration(8000);

2.Test with the following code. The dialog is displayed in 8 seconds. But the documentation says: "the dialog will pop up after the minimumDuration time or as soon as any progress is set". Though the behavior is different with the documentation, I think the current behavior is acceptable.

QProgressDialog* dlg = new QProgressDialog("Test", "cancel", 0, 10);
dlg->setMinimumDuration(8000);
dlg->setValue(0);

3.Test with the following code. The dialog is never displayed. But the documentation says: "the dialog will pop up after the minimumDuration time or as soon as any progress is set".

QProgressDialog* dlg = new QProgressDialog("Test", "cancel", 0, 10);
dlg->setMinimumDuration(8000);
dlg->setValue(1);

4.Test with the following code. The behavior is same as item 2.

QProgressDialog* dlg = new QProgressDialog("Test", "cancel", 0, 10);
dlg->setMinimumDuration(8000);
dlg->setValue(0);
dlg->setValue(1);

5.Test with the following code. The dialog is displayed as soon as set the progress value to 1. Why does Sleep() function affect the behavior here?

QProgressDialog* dlg = new QProgressDialog("Test", "cancel", 0, 10);
dlg->setMinimumDuration(8000);
dlg->setValue(0);
::Sleep(static_cast<DWORD>(1000));
dlg->setValue(1);

6.Test with the code below. The dialog is displayed immediately, but I set MinimumDuration to 5. Is it a problem?

QProgressDialog* dialog = new QProgressDialog("Message", "Close", 1, 10);
dialog->setMinimumDuration(5000);
dialog->setValue(0); 
dialog->setValue(1); 

I test on Windoes 7. What are the issues? What are the correct behaviors?

like image 421
ldlchina Avatar asked Feb 09 '23 10:02

ldlchina


2 Answers

Indeed the information is scattered around so it seems to make no sense. But there is a precious hint in the doc :

QProgressDialog ... estimates the time the operation will take (based on time for steps), and only shows itself if that estimate is beyond minimumDuration() (4 seconds by default).

The dialog seems to use the value property to approximate the time required for steps. And it is seems that value property by default is not set

value property :

For the progress dialog to work as expected, you should initially set this property to 0 and finally set it to QProgressDialog::maximum();

Indeed, dialog->value() returns -1 in my machine after construction.

To wrap up :

  1. Not setting value is an issue. You have to set value sometimes to make it work.
  2. The dialog is shown as soon as it interpolates that the total amount of work is going to take more than minimumDuration

  3. Setting a value to anything lower than QProgressDialog::minimum(), which is the case by default, causes the progressbar to stay hidden.

  4. Your second cases set the value to 0 = minimum. After 8 seconds, you still havent updated that value. which means the processing of a single item take more than 8 seconds. Should show.
  5. You should modify the value from 0 -> minimum -> maximum for proper behavior. Your third case, fail to do this because value goes from -1 to 1, without being set to 0 = minimum. Unspecified, in this version doesnt show.
  6. Your 4th case means "the first processing took 0 second, the second is not done yet". So the minimumDuration behavior kicks in. Should show.
  7. Now that there is one second duration for the first task (case 5), the dialog approximates that 10 tasks are going to take 10s, which is bigger than 8s, so the dialog is shown as soon as dlg->setValue(1); is executed.
like image 148
UmNyobe Avatar answered Feb 10 '23 23:02

UmNyobe


I tested this on OS X, with Qt 5 and get the same results

Looking closer at the documentation for setValue, it states: -

For the progress dialog to work as expected, you should initially set this property to QProgressDialog::minimum() and finally set it to QProgressDialog::maximum(); you can call setValue() any number of times in-between.

With this in mind, it works as expected, as can be seen when you first set the value to zero, then another value.

QProgressDialog* dlg = new QProgressDialog("Test", "cancel", 0, 10);
dlg->setMinimumDuration(8000);
dlg->setValue(0);
dlg->setValue(1);

So, I think the documentation for setMinimumDuration should probably link to this too, but the behaviour is correct according to the documentation, when taking setValue into account.

like image 44
TheDarkKnight Avatar answered Feb 11 '23 01:02

TheDarkKnight