QDBusArgument: disambiguate between QMap on std::pair and std::map

For QMap on a std::pair, QMap::iterator{}.operator->() would result in a
type that has "first" and "second" members: std::pair itself. But it
would be wrong to marshall and demarshall the first and second elements
thereof as the key and value, so give preference to the .key() and
.value() selection, which would store the std::pair as the type.

Fixes: QTBUG-123401
Pick-to: 6.6 6.5
Change-Id: I6818d78a57394e37857bfffd17bd69bb692dd03b
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 5401a9a6cd3263eda15911c3fbfc81ebea2e798f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-03-16 18:41:27 -07:00 committed by Qt Cherry-pick Bot
parent fbdcae954e
commit 9ffed81b15
3 changed files with 20 additions and 1 deletions

View File

@ -302,7 +302,11 @@ using IfAssociativeIteratorHasKeyAndValue =
template <typename Iterator>
using IfAssociativeIteratorHasFirstAndSecond =
std::enable_if_t<qxp::is_detected_v<FirstAndSecondTest, Iterator>, bool>;
std::enable_if_t<
std::conjunction_v<
std::negation<qxp::is_detected<KeyAndValueTest, Iterator>>,
qxp::is_detected<FirstAndSecondTest, Iterator>
>, bool>;
template <typename Iterator>
using MoveBackwardsTest = decltype(

View File

@ -152,7 +152,9 @@ void commonInit()
qDBusRegisterMetaType<QMap<QDBusObjectPath, QString> >();
qDBusRegisterMetaType<QMap<qlonglong, QDateTime> >();
qDBusRegisterMetaType<QMap<QDBusSignature, QString> >();
qDBusRegisterMetaType<QMap<QString, std::pair<int, int>>>();
qDBusRegisterMetaType<std::pair<int, int>>();
qDBusRegisterMetaType<MyStruct>();
qDBusRegisterMetaType<MyVariantMapStruct>();
qDBusRegisterMetaType<QList<MyVariantMapStruct> >();
@ -471,6 +473,8 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2)
return compare<QMap<qlonglong, QDateTime> >(arg, v2);
else if (id == qMetaTypeId<QMap<QDBusSignature, QString> >())
return compare<QMap<QDBusSignature, QString> >(arg, v2);
else if (id == qMetaTypeId<QMap<QString, std::pair<int, int>>>())
return compare<QMap<QString, std::pair<int, int>>>(arg, v2);
else if (id == qMetaTypeId<QList<QByteArray> >())
return compare<QList<QByteArray> >(arg, v2);

View File

@ -476,6 +476,17 @@ void tst_QDBusMarshall::sendMaps_data()
QTest::newRow("gs-map") << QVariant::fromValue(gsmap) << "a{gs}"
<< "[Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]";
QMap<QString, std::pair<int, int>> siimap;
QTest::newRow("empty-sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}"
<< "[Argument: a{s(ii)} {}]";
siimap["0,0"] = { 0, 0 };
siimap["1,-1"] = { 1, -1 };
QTest::newRow("sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}"
<< "[Argument: a{s(ii)} {"
"\"0,0\" = [Argument: (ii) 0, 0], "
"\"1,-1\" = [Argument: (ii) 1, -1]"
"}]";
if (fileDescriptorPassing) {
svmap["zzfiledescriptor"] = QVariant::fromValue(QDBusUnixFileDescriptor(fileDescriptorForTest()));
QTest::newRow("sv-map1-fd") << QVariant::fromValue(svmap) << "a{sv}"