summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-11-09 15:23:52 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-11-10 11:23:55 +0100
commit16d412da4c0d7ef4776604b906fccb8132a7712d (patch)
tree608c3c2824a1f6d70f87b4cd086e2c1913e76c65
parentf95691b8afa5e73fc31ab1d654bfceb4bddb53a0 (diff)
QSignalSpy: Use QMetaType instead of metatype id in initArgs
The RegisterMethodArgumentMetaType had been changed to take a QMetaType instead of a type id in 0161f00e5043090f22b23de9822c09062b17d675. Unfortunately, the usage of it in QSignalSpy was missed. This patch adjusts the metacall to correctly use a QMetaType. Moreover, use parameterMetaType instead of parameterType to benefit from metatypes which are already resolved at compile time. Task-number: QTBUG-88260 Fixes: QTBUG-88356 Change-Id: Id8fa46581a005d62818971ea24d8aa2e39dcd6d0 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/testlib/qsignalspy.h10
-rw-r--r--tests/auto/testlib/qsignalspy/tst_qsignalspy.cpp24
2 files changed, 28 insertions, 6 deletions
diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h
index 1d42995b4e..3ba56749ea 100644
--- a/src/testlib/qsignalspy.h
+++ b/src/testlib/qsignalspy.h
@@ -192,23 +192,21 @@ private:
{
args.reserve(member.parameterCount());
for (int i = 0; i < member.parameterCount(); ++i) {
- int tp = member.parameterType(i);
- if (tp == QMetaType::UnknownType && obj) {
+ QMetaType tp = member.parameterMetaType(i);
+ if (!tp.isValid() && obj) {
void *argv[] = { &tp, &i };
QMetaObject::metacall(const_cast<QObject*>(obj),
QMetaObject::RegisterMethodArgumentMetaType,
member.methodIndex(), argv);
- if (tp == -1)
- tp = QMetaType::UnknownType;
}
- if (tp == QMetaType::UnknownType) {
+ if (!tp.isValid()) {
qWarning("QSignalSpy: Unable to handle parameter '%s' of type '%s' of method '%s',"
" use qRegisterMetaType to register it.",
member.parameterNames().at(i).constData(),
member.parameterTypes().at(i).constData(),
member.name().constData());
}
- args << tp;
+ args << tp.id();
}
}
diff --git a/tests/auto/testlib/qsignalspy/tst_qsignalspy.cpp b/tests/auto/testlib/qsignalspy/tst_qsignalspy.cpp
index 9555c2a844..fcd33f5af4 100644
--- a/tests/auto/testlib/qsignalspy/tst_qsignalspy.cpp
+++ b/tests/auto/testlib/qsignalspy/tst_qsignalspy.cpp
@@ -57,6 +57,7 @@ private slots:
void spyFunctionPointerWithBasicArgs();
void spyFunctionPointerWithPointers();
void spyFunctionPointerWithQtClasses();
+ void spyFunctionPointerWithCustomClass();
void spyFunctionPointerWithBasicQtClasses();
void spyFunctionPointerWithQtTypedefs();
@@ -72,6 +73,8 @@ private slots:
void spyOnMetaMethod_invalid_data();
};
+struct CustomType {};
+
class QtTestObject: public QObject
{
Q_OBJECT
@@ -152,6 +155,8 @@ void tst_QSignalSpy::spyWithPointers()
QCOMPARE(*static_cast<int * const *>(args.at(1).constData()), &i2);
}
+struct CustomType2;
+
class QtTestObject2: public QObject
{
Q_OBJECT
@@ -163,6 +168,8 @@ signals:
void sig3(QObject *o);
void sig4(QChar c);
void sig5(const QVariant &v);
+ void sig6(CustomType );
+ void sig7(CustomType2 *);
};
void tst_QSignalSpy::spyWithBasicQtClasses()
@@ -383,6 +390,23 @@ void tst_QSignalSpy::spyFunctionPointerWithQtClasses()
QCOMPARE(qvariant_cast<QChar>(spy3.value(0).value(0)), QChar('A'));
}
+void tst_QSignalSpy::spyFunctionPointerWithCustomClass()
+{
+ QtTestObject2 obj;
+ {
+ QSignalSpy spy(&obj, &QtTestObject2::sig6);
+ emit obj.sig6({});
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.at(0).count(), 1);
+ QCOMPARE(spy.at(0).at(0).typeName(), "CustomType");
+ }
+
+ {
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg, "QSignalSpy: Unable to handle parameter '' of type 'CustomType2*' of method 'sig7', use qRegisterMetaType to register it.");
+ QSignalSpy spy(&obj, &QtTestObject2::sig7);
+ }
+}
+
void tst_QSignalSpy::spyFunctionPointerWithQtTypedefs()
{
QtTestObject3 obj;