diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 6ac2e1cec29..e504d7f5357 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -1281,9 +1281,10 @@ QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos, const bool minus = min <= 0; const QString group(locale.groupSeparator()); - const uint groupUcs = (group.size() > 1 && group.at(0).isHighSurrogate() - ? QChar::surrogateToUcs4(group.at(0), group.at(1)) - : group.at(0).unicode()); + const uint groupUcs = (group.isEmpty() ? 0 : + (group.size() > 1 && group.at(0).isHighSurrogate() + ? QChar::surrogateToUcs4(group.at(0), group.at(1)) + : group.at(0).unicode())); switch (len) { case 0: state = max != min ? QValidator::Intermediate : QValidator::Invalid; @@ -1306,7 +1307,7 @@ QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos, default: break; } - if (copy.at(0) == locale.groupSeparator()) { + if (groupUcs && copy.startsWith(group)) { QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; state = QValidator::Invalid; goto end; @@ -1322,8 +1323,9 @@ QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos, state = QValidator::Invalid; goto end; } - for (int i=dec + 1; i -1000 && copy.contains(group)) { + if (max < 1000 && min > -1000 && groupUcs && copy.contains(group)) { state = QValidator::Invalid; QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; goto end; @@ -1361,7 +1364,7 @@ QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos, const int len = copy.size(); for (int i = 0; i < len - 1;) { - if (QStringView(copy).mid(i).startsWith(group)) { + if (groupUcs && QStringView{copy}.sliced(i).startsWith(group)) { if (QStringView(copy).mid(i + group.size()).startsWith(group)) { QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; state = QValidator::Invalid; @@ -1374,7 +1377,8 @@ QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos, } QString copy2 = copy; - copy2.remove(group); + if (groupUcs) + copy2.remove(group); num = locale.toDouble(copy2, &ok); QSBDEBUG() << group << num << copy2 << ok;