diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index 270a4833a34..b9ab4cbb3fd 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -479,11 +479,13 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type) DWORD flags = 0; // keep the same conditional as timeFormat() above - if (type == QLocale::ShortFormat) - flags = TIME_NOSECONDS; + const QString format = type == QLocale::ShortFormat + ? getLocaleInfo(LOCALE_SSHORTTIME).toString() + : QString(); + auto formatStr = reinterpret_cast(format.isEmpty() ? nullptr : format.utf16()); wchar_t buf[255]; - if (getTimeFormat(flags, &st, NULL, buf, 255)) { + if (getTimeFormat(flags, &st, formatStr, buf, int(std::size(buf)))) { QString text = QString::fromWCharArray(buf); if (substitution() == SAlways) text = substituteDigits(std::move(text)); diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index f464b427a0c..4897218fcc3 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -2314,7 +2314,7 @@ void tst_QLocale::windowsDefaultLocale() locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat)); QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat), QStringView(u"\u3021@\u3021\u3022@\u3021\u3029\u3027\u3024")); - const QString expectedFormattedShortTime = QStringView(u"\u3021^\u3022").toString(); + const QString expectedFormattedShortTime = QStringView(u"\u3021^\u3022^\u3023").toString(); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::ShortFormat), expectedFormattedShortTime); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat), locale.toString(QTime(1,2,3), QLocale::ShortFormat));