rbutil: Fix build info list handling with Qt6.

With Qt6 we need to check the type differently or we'd convert a
stringlist to a string.

Change-Id: I00a7a73535503b97f40edb51099a332902e881e0
This commit is contained in:
Dominik Riebeling 2022-03-23 20:11:31 +01:00
parent f3b19de594
commit 238cd13469
2 changed files with 14 additions and 10 deletions

View file

@ -137,9 +137,9 @@ QVariant PlayerBuildInfo::value(BuildInfo item, BuildType type)
break; break;
} }
QVariant result = QString(); QVariant result;
if (!serverInfo) if (!serverInfo)
return result; return QString();
QStringList version = serverInfo->value(buildtypename + "/" + target, "").toStringList(); QStringList version = serverInfo->value(buildtypename + "/" + target, "").toStringList();
serverinfo.replace(":build:", buildtypename); serverinfo.replace(":build:", buildtypename);
serverinfo.replace(":version:", version.at(0)); serverinfo.replace(":version:", version.at(0));
@ -149,7 +149,7 @@ QVariant PlayerBuildInfo::value(BuildInfo item, BuildType type)
// For invalid data return an empty string. // For invalid data return an empty string.
if(version.at(0).isEmpty()) { if(version.at(0).isEmpty()) {
LOG_INFO() << serverinfo << "(version invalid)"; LOG_INFO() << serverinfo << "(version invalid)";
return result; return QString();
} }
if(!serverinfo.isEmpty()) if(!serverinfo.isEmpty())
result = serverInfo->value(serverinfo); result = serverInfo->value(serverinfo);
@ -189,7 +189,11 @@ QVariant PlayerBuildInfo::value(BuildInfo item, BuildType type)
// if the value is a string we can replace some patterns. // if the value is a string we can replace some patterns.
// if we cannot convert it (f.e. for a QStringList) we leave as-is, since // if we cannot convert it (f.e. for a QStringList) we leave as-is, since
// the conversion would return an empty type. // the conversion would return an empty type.
if (result.canConvert(QMetaType::QString)) #if QT_VERSION < 0x060000
if (result.type() == QVariant::String)
#else
if (result.metaType().id() == QMetaType::QString)
#endif
result = result.toString() result = result.toString()
.replace("%TARGET%", target) .replace("%TARGET%", target)
.replace("%VERSION%", version.at(0)); .replace("%VERSION%", version.at(0));

View file

@ -212,10 +212,10 @@ void TestPlayerBuildInfo::testBuildInfo()
RbSettings::setValue(RbSettings::CurrentPlatform, target); RbSettings::setValue(RbSettings::CurrentPlatform, target);
QVariant result = PlayerBuildInfo::instance()->value(item, type); QVariant result = PlayerBuildInfo::instance()->value(item, type);
if(result.canConvert(QMetaType::QString)) if(result.canConvert(QMetaType::QStringList))
QCOMPARE(result.toString(), QString(expected));
else
QCOMPARE(result.toStringList().join(","), QString(expected)); QCOMPARE(result.toStringList().join(","), QString(expected));
else
QCOMPARE(result.toString(), QString(expected));
} }
@ -252,10 +252,10 @@ void TestPlayerBuildInfo::testPlayerInfo()
QFETCH(QString, expected); QFETCH(QString, expected);
QVariant result = PlayerBuildInfo::instance()->value(item, target); QVariant result = PlayerBuildInfo::instance()->value(item, target);
if(result.canConvert(QMetaType::QString)) if(result.canConvert(QMetaType::QStringList))
QCOMPARE(result.toString(), QString(expected));
else
QCOMPARE(result.toStringList().join(","), QString(expected)); QCOMPARE(result.toStringList().join(","), QString(expected));
else
QCOMPARE(result.toString(), QString(expected));
} }