From: Manuel Nickschas Date: Tue, 27 Mar 2012 20:04:03 +0000 (+0200) Subject: Properly handle QGenericReturnArgument X-Git-Tag: 0.9-beta1~82 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=565743a41c93de874cb79fd145b22e2422bb754e Properly handle QGenericReturnArgument Using the memory address of the QVariant that acts as buffer is bad. While we got lucky with Qt4, and this worked by accident, it leads to subtle and not-so-subtle segfaults when used with Qt5. Instead, using QVariant::data() makes sure that implicitly shared data is properly detached. --- diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index 8667a593..ac62f080 100644 --- a/src/common/syncableobject.cpp +++ b/src/common/syncableobject.cpp @@ -105,15 +105,14 @@ QVariantMap SyncableObject::toVariantMap() { qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.signature() << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName()); continue; } - QVariant value = QVariant(variantType); - QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), &value); + + QVariant value(variantType, (const void *) 0); + QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), value.data()); QMetaObject::invokeMethod(this, methodname.toAscii(), genericvalue); properties[SignalProxy::ExtendedMetaObject::methodBaseName(method)] = value; } - // properties["Payload"] = QByteArray(10000000, 'a'); // for testing purposes return properties; - } void SyncableObject::fromVariantMap(const QVariantMap &properties) {