diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-03-03 00:11:13 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-03-04 01:26:53 +0100 |
commit | e93bf391fa3df4498da0f3526f4c89dd35637103 (patch) | |
tree | 52a020ac64c823607a14e2b0b4022c10827acf73 /src/testlib/qtestcase.h | |
parent | 8e56a7bc6b01142129f6e316410df6f384983391 (diff) |
Fix QTest::toString() over QT_TYPESAFE_FLAGS QFlags
QT_TYPESAFE_FLAGS allows explicit casts only to QFlags<T>::Int, which
is either int or unsigned int. The cast to the resp. other type fails.
To fix, first convert to QFlags<T>::Int with toInt(), and only then
cast to int or unsigned int.
Fixes: QTBUG-101399
Pick-to: 6.3
Change-Id: Ie74d53adc601cdf19708265b040092780676058f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r-- | src/testlib/qtestcase.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 80cece7f9a..adfc987862 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -290,7 +290,7 @@ namespace QTest inline typename std::enable_if<QtPrivate::IsQEnumHelper<F>::Value, char*>::type toString(QFlags<F> f) { const QMetaEnum me = QMetaEnum::fromType<F>(); - return qstrdup(me.valueToKeys(int(f)).constData()); + return qstrdup(me.valueToKeys(int(f.toInt())).constData()); } template <typename F> // Fallback: Output hex value @@ -298,7 +298,7 @@ namespace QTest { const size_t space = 3 + 2 * sizeof(unsigned); // 2 for 0x, two hex digits per byte, 1 for '\0' char *msg = new char[space]; - qsnprintf(msg, space, "0x%x", unsigned(f)); + qsnprintf(msg, space, "0x%x", unsigned(f.toInt())); return msg; } |