diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2017-04-18 12:08:12 +0200 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2017-04-22 11:25:49 +0000 |
commit | d4cdc4542609e61d04802902d73c693faa8d8969 (patch) | |
tree | ac3ef546a85667205e96b6d38cbe2d575af0de8b /src/corelib/kernel | |
parent | 23287dfb15bb2bee19d2fa3530c030a6b75facfa (diff) |
Fix QMetaMethod::invoke and automatic type registration
This was simply not working for two reasons:
- The index passed to QMetaObject::metacall was not right (there was an offset
because of the return type)
- If the registration succeeded, the arguments were not even initialized.
The tests in tst_moc always called QMetaMethod::parameterType before calling invoke,
which was properly registering the type. So this was not seen in the tests before.
[ChangeLog][QtCore][QMetaMethod] Fixed crash in invoke() with QueuedConnection and
types whose metatype gets automatically registered.
Task-number: QTBUG-60185
Change-Id: I4247628484214fba0a8acc1813ed8f112f59c888
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 2e0dd8e5d2..a8003f7e46 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -2241,12 +2241,10 @@ bool QMetaMethod::invoke(QObject *object, for (int i = 1; i < paramCount; ++i) { types[i] = QMetaType::type(typeNames[i]); - if (types[i] != QMetaType::UnknownType) { - args[i] = QMetaType::create(types[i], param[i]); - ++nargs; - } else if (param[i]) { + if (types[i] == QMetaType::UnknownType && param[i]) { // Try to register the type and try again before reporting an error. - void *argv[] = { &types[i], &i }; + int index = nargs - 1; + void *argv[] = { &types[i], &index }; QMetaObject::metacall(object, QMetaObject::RegisterMethodArgumentMetaType, idx_relative + idx_offset, argv); if (types[i] == -1) { @@ -2261,6 +2259,10 @@ bool QMetaMethod::invoke(QObject *object, return false; } } + if (types[i] != QMetaType::UnknownType) { + args[i] = QMetaType::create(types[i], param[i]); + ++nargs; + } } QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction, |