QMetaMethod::invoke: compare the QMetaType id of the return types

Since Qt5, the QMetaObject do not contains the string name of the
builtin types, but only the QMetaType id. QMetaMethod::typeName
convert back from the id to the string. But if the type is aliased,
the string of the main type is returned.

This was the case for example for qint64 which is transformed to
"qlonglong".

This causes a regression in QMetaType::invoke when trying to invoke a
method which return an aliased type, since the string comparison would
fail.

Fix the problem by also comparing the metatype id.

Changelog: QMetaMethod::invoke: Fix return of aliased meta type

Task-number: QTBUG-33222
Change-Id: Iec7b99dcbf7b23eb818de74f413e4451ce510ac4
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
This commit is contained in:
Olivier Goffart 2013-08-29 12:53:18 +02:00 committed by The Qt Project
parent e59a5f9fdc
commit b49327145e
2 changed files with 18 additions and 2 deletions

View File

@ -42,6 +42,7 @@
#include "qmetaobject.h"
#include "qmetatype.h"
#include "qobject.h"
#include "qmetaobject_p.h"
#include <qcoreapplication.h>
#include <qcoreevent.h>
@ -2098,8 +2099,12 @@ bool QMetaMethod::invoke(QObject *object,
if (qstrcmp(returnValue.name(), retType) != 0) {
// normalize the return value as well
QByteArray normalized = QMetaObject::normalizedType(returnValue.name());
if (qstrcmp(normalized.constData(), retType) != 0)
return false;
if (qstrcmp(normalized.constData(), retType) != 0) {
// String comparison failed, try compare the metatype.
int t = returnType();
if (t == QMetaType::UnknownType || t != QMetaType::type(normalized))
return false;
}
}
}

View File

@ -328,6 +328,7 @@ public slots:
QObject *sl11();
const char *sl12();
QList<QString> sl13(QList<QString> l1);
qint64 sl14();
void testSender();
void testReference(QString &str);
@ -395,6 +396,9 @@ const char *QtTestObject::sl12()
{ slotResult = "sl12"; return "foo"; }
QList<QString> QtTestObject::sl13(QList<QString> l1)
{ slotResult = "sl13"; return l1; }
qint64 QtTestObject::sl14()
{ slotResult = "sl14"; return Q_INT64_C(123456789)*123456789; }
void QtTestObject::testReference(QString &str)
{ slotResult = "testReference:" + str; str = "gotcha"; }
@ -513,6 +517,13 @@ void tst_QMetaObject::invokeMetaMember()
QCOMPARE(returnValue, argument);
QCOMPARE(obj.slotResult, QString("sl13"));
// return qint64
qint64 return64;
QVERIFY(QMetaObject::invokeMethod(&obj, "sl14",
Q_RETURN_ARG(qint64, return64)));
QCOMPARE(return64, Q_INT64_C(123456789)*123456789);
QCOMPARE(obj.slotResult, QString("sl14"));
//test signals
QVERIFY(QMetaObject::invokeMethod(&obj, "sig0"));
QCOMPARE(obj.slotResult, QString("sl0"));