QProgressBar: don't lose precision in text()
When qreal is float, it cannot represent all values an int can take, so we may lose precision in the expression qreal(d->value) - d->minimum as opposed to the exact result qint64(d->value) - d->minimum' For lack of trying, I do not know of a value where this would change the resulting 'progress' value, but better be safe than sorry, and use the 64-bit integer expression instead. Found while reviewing integer arithmetic in QProgressBar as part of the fix for QTBUG-57857. While touching the line, make the (intended) double → int truncation explicit, by using a static_cast. Change-Id: I03dbfce24c709310c3bbad9487a2bf0d1d78137a Reviewed-by: David Faure <david.faure@kdab.com>bb10
parent
e35c993020
commit
a3d0983f59
|
|
@ -485,7 +485,7 @@ QString QProgressBar::text() const
|
|||
return result;
|
||||
}
|
||||
|
||||
int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps;
|
||||
const auto progress = static_cast<int>((qint64(d->value) - d->minimum) * 100.0 / totalSteps);
|
||||
result.replace(QLatin1String("%p"), locale.toString(progress));
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue