QProgressDialog:关于MinimumDuration的问题

QProgressDialog: problems about MinimumDuration

我正在使用 QT 4.8.5。我在带有 MinimumDuration 的 QProgressDialog 上遇到了一些问题。 这是文档:http://doc.qt.io/qt-4.8/qprogressdialog.html#minimumDuration-prop.

1.Test 使用以下代码。对话框根本不显示。但是文档说:“对话框将在 minimumDuration 时间 之后或设置任何进度后立即弹出”。

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

2.Test 使用以下代码。该对话框将在 8 秒后显示。但是文档说:"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(0);

3.Test 使用以下代码。该对话框永远不会显示。但是文档说:“对话框将在 minimumDuration 时间后或设置任何进度后立即弹出”。

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

4.Test 使用以下代码。行为与第 2 项相同。

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

5.Test 使用以下代码。一旦将进度值设置为 1,就会显示该对话框。为什么 Sleep() 函数会影响此处的行为?

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

6.Test 使用下面的代码。立即显示对话框,但我将 MinimumDuration 设置为 5。是否有问题?

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

我在Windoes 7上测试,有什么问题?什么是正确的行为?

我在 OS X 上用 Qt 5 测试了这个,得到了相同的结果

仔细查看 setValue 的文档,它指出:-

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.

考虑到这一点,它会按预期工作,正如您首先将该值设置为零,然后再设置另一个值时所看到的那样。

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

所以,我认为 setMinimumDuration 的文档可能也应该 link,但根据文档,在考虑 setValue 时行为是正确的。

确实信息散乱,所以看起来毫无意义。但是有一个 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).

该对话框似乎使用 value 属性 来估算步骤所需的时间。而且似乎默认值 属性 未设置

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();

确实,dialog->value() returns -1 在我的机器上构建后。

总结:

  1. 不设置值是个问题。您 有时必须设置 值才能使其正常工作。
  2. 一旦提示 总工作量 的工作时间超过 minimumDuration[=49],就会显示对话框=]

  3. 将值设置为低于 QProgressDialog::minimum() 的任何值(默认情况下都是如此)会导致进度条保持隐藏状态。

  4. 您的第二个案例将值设置为 0 = minimum。 8 秒后,您仍然没有更新该值。这意味着单个项目的处理时间超过 8 秒。应该显示。
  5. 应该 修改 0 -> minimum -> maximum 的值以获得正确的行为。您的第三种情况,未能执行此操作,因为值从 -1 变为 1,但未设置为 0 = 最小值。未指定,在此版本中未显示。
  6. 您的第 4 个案例意味着 "the first processing took 0 second, the second is not done yet"。所以 minimumDuration 行为开始。应该显示。
  7. 现在第一个任务(案例 5)有一秒的持续时间,对话框 近似 10 个任务将要完成耗时 10 秒,比 8s 大,所以一旦执行 dlg->setValue(1); 就会显示对话框。