diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp
index 78612f31816b8a7ff4748d8bf4da2ba1b7d00389..b5cc630bfe58ae56ef26a6a7dfcebf1d9a15d6d0 100644
--- a/src/widgets/dialogs/qprogressdialog.cpp
+++ b/src/widgets/dialogs/qprogressdialog.cpp
@@ -662,6 +662,7 @@ void QProgressDialog::setValue(int progress)
                     int estimate;
                     int totalSteps = maximum() - minimum();
                     int myprogress = progress - minimum();
+                    if (myprogress == 0) myprogress = 1;
                     if ((totalSteps - myprogress) >= INT_MAX / elapsed)
                         estimate = (totalSteps - myprogress) / myprogress * elapsed;
                     else
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
index d49f356d8c426fa20d32cd3553cff768cd490747..68502f0d8d4a2b2a8504b34df5277939ab159dd3 100644
--- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
+++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
@@ -46,6 +46,7 @@
 #include <qdebug.h>
 #include <qprogressdialog.h>
 #include <qlabel.h>
+#include <qthread.h>
 
 class tst_QProgressDialog : public QObject
 {
@@ -58,6 +59,7 @@ public:
 private slots:
     void getSetCheck();
     void task198202();
+    void QTBUG_31046();
 };
 
 tst_QProgressDialog::tst_QProgressDialog()
@@ -149,5 +151,14 @@ void tst_QProgressDialog::task198202()
     QCOMPARE(dlg.sizeHint().height(), futureHeight);
 }
 
+void tst_QProgressDialog::QTBUG_31046()
+{
+    QProgressDialog dlg("", "", 50, 60);
+    dlg.setValue(0);
+    QThread::msleep(200);
+    dlg.setValue(50);
+    QCOMPARE(50, dlg.value());
+}
+
 QTEST_MAIN(tst_QProgressDialog)
 #include "tst_qprogressdialog.moc"