summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-03-03 00:11:13 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-03-04 07:03:20 +0000
commitb72d7931f1b54b40883737322b05cdab35a312fa (patch)
tree25d992853b1f9b4de80fd4f7d0aaabac41d836f6 /src/testlib
parentea39203474658314c81e3a45bcb4bd849753eda1 (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 Change-Id: Ie74d53adc601cdf19708265b040092780676058f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit e93bf391fa3df4498da0f3526f4c89dd35637103) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.h4
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;
}