tst_QMetaObject: add more QList/QVector tests

Check that a slot that was declared using QVector ends up stored as,
and can be called with, QList (and QVector).

Also check that the various indexOf*() methods do the QVector</QList<
normalization, even though they're documented to require normalized
input. A subsequent patch will deprecate that behavior, so make sure
we don't break it as we change it.

Amends 1fa31be7ce3a6899f1c1597311d7593648ecd1d8.

Pick-to: 6.9 6.8 6.5
Task-number: QTBUG-135572
Change-Id: Id28bf3c4163099f07213bfbf7d296b4fd76b71a5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit 5c563a98a5ffe2a72a641bfa9ed30e17ecffd893)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-05-23 16:13:35 +02:00 committed by Qt Cherry-pick Bot
parent a4db2f7313
commit 023e36e0e7

View File

@ -501,6 +501,8 @@ public:
Q_INVOKABLE QtTestObject(QObject *parent);
Q_INVOKABLE QtTestObject(QObject *parent, int, int);
Q_INVOKABLE QtTestObject(QObject *parent, int);
Q_INVOKABLE QtTestObject(QList<int>, QObject *parent) : QtTestObject(parent) {}
Q_INVOKABLE QtTestObject(QObject *parent, QVector<int>) : QtTestObject(parent) {}
public slots:
void sl0();
@ -520,6 +522,8 @@ public slots:
QObject *sl11();
const char *sl12();
QList<QString> sl13(QList<QString> l1);
// check Qt 6 QVector/QList alias:
QVector<QString> sl13v(QVector<QString> v1);
qint64 sl14();
qlonglong *sl15(qlonglong *);
MyForwardDeclaredType *sl16(MyForwardDeclaredType *);
@ -628,6 +632,8 @@ const char *QtTestObject::sl12()
{ slotResult = "sl12"; return "foo"; }
QList<QString> QtTestObject::sl13(QList<QString> l1)
{ slotResult = "sl13"; return l1; }
QVector<QString> QtTestObject::sl13v(QVector<QString> v1)
{ slotResult = "sl13v"; return v1; }
qint64 QtTestObject::sl14()
{ slotResult = "sl14"; return Q_INT64_C(123456789)*123456789; }
qlonglong *QtTestObject::sl15(qlonglong *ptr)
@ -797,11 +803,50 @@ void tst_QMetaObject::invokeMetaMember()
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
// same, testing the QList/QVector aliasing:
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13",
Q_RETURN_ARG(QVector<QString>, returnValue),
Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13",
Q_RETURN_ARG(QList<QString>, returnValue),
Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13"_L1);
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13",
Q_RETURN_ARG(QVector<QString>, returnValue),
Q_ARG(QList<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13"_L1);
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v",
Q_RETURN_ARG(QList<QString>, returnValue),
Q_ARG(QList<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v",
Q_RETURN_ARG(QVector<QString>, returnValue),
Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v",
Q_RETURN_ARG(QList<QString>, returnValue),
Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v",
Q_RETURN_ARG(QVector<QString>, returnValue),
Q_ARG(QList<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
returnValue.clear();
// return qint64
qint64 return64;
@ -970,6 +1015,12 @@ void tst_QMetaObject::invokeMetaMemberNoMacros()
argument));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v",
qReturnArg(returnValue),
argument));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
// return qint64
qint64 return64;
@ -1589,12 +1640,25 @@ void tst_QMetaObject::invokeBlockingQueuedMetaMember()
Q_ARG(QList<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
returnValue.clear();
// same, testing QVector/QList aliasing:
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QVector<QString>, returnValue),
Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QList<QString>, returnValue),
Q_ARG(QList<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QVector<QString>, returnValue),
Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
// return qint64
qint64 return64;
@ -1768,6 +1832,12 @@ void tst_QMetaObject::invokeBlockingQueuedMetaMemberNoMacros()
argument));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
returnValue.clear();
QVERIFY(QMetaObject::invokeMethod(&obj, "sl13v", Qt::BlockingQueuedConnection,
qReturnArg(returnValue),
argument));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, "sl13v"_L1);
// return qint64
qint64 return64;
@ -2641,6 +2711,13 @@ void tst_QMetaObject::metaMethod()
QVERIFY(method.invoke(&obj, Q_ARG(QString, "1"), Q_ARG(QString, "2"), Q_ARG(QString, "3"), Q_ARG(QString, "4"), Q_ARG(QString, "5")));
QCOMPARE(obj.slotResult, QString("sl5:12345"));
// check Qt 6 QVector/QList alias:
index = QtTestObject::staticMetaObject.indexOfMethod("sl13v(QVector<QString>)");
QVERIFY(index > 0);
index = QtTestObject::staticMetaObject.indexOfMethod("sl13v(QList<QString>)");
QVERIFY(index > 0);
index = QtTestObject::staticMetaObject.indexOfMethod("sl13(QVector<QString>)");
QVERIFY(index > 0);
index = QtTestObject::staticMetaObject.indexOfMethod("sl13(QList<QString>)");
QVERIFY(index > 0);
QMetaMethod sl13 = QtTestObject::staticMetaObject.method(index);
@ -2654,6 +2731,19 @@ void tst_QMetaObject::metaMethod()
QVERIFY(sl13.invoke(&obj, Q_RETURN_ARG(QList<QString>, returnValue), Q_ARG(QVector<QString>, argument)));
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
index = QtTestObject::staticMetaObject.indexOfConstructor("QtTestObject(QObject*,QList<int>)");
QVERIFY(index > 0);
index = QtTestObject::staticMetaObject.indexOfConstructor("QtTestObject(QObject*,QVector<int>)");
QVERIFY(index > 0);
QCOMPARE(QtTestObject::staticMetaObject.constructor(index).methodSignature(),
"QtTestObject(QObject*,QList<int>)"_L1);
index = QtTestObject::staticMetaObject.indexOfConstructor("QtTestObject(QList<int>,QObject*)");
QVERIFY(index > 0);
index = QtTestObject::staticMetaObject.indexOfConstructor("QtTestObject(QVector<int>,QObject*)");
QVERIFY(index > 0);
QCOMPARE(QtTestObject::staticMetaObject.constructor(index).methodSignature(),
"QtTestObject(QList<int>,QObject*)"_L1);
}
// this is a copy-paste-adapt of the above
@ -2694,6 +2784,9 @@ void tst_QMetaObject::metaMethodNoMacro()
QVERIFY(method.invoke(&obj, QStringLiteral("1"), QStringLiteral("2"), QStringLiteral("3"), QStringLiteral("4"), QStringLiteral("5")));
QCOMPARE(obj.slotResult, QString("sl5:12345"));
// check Qt 6 QVector/QList alias:
index = QtTestObject::staticMetaObject.indexOfMethod("sl13(QVector<QString>)");
QVERIFY(index > 0);
index = QtTestObject::staticMetaObject.indexOfMethod("sl13(QList<QString>)");
QVERIFY(index > 0);
QMetaMethod sl13 = QtTestObject::staticMetaObject.method(index);