From 57d44eafac4d353d1523e93cc7613debc1826e94 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Mon, 24 Mar 2008 18:01:22 +0000 Subject: [PATCH] - fixed crashes caused by return types of init methods that were unknown to Qt's meta system - minor tweaks to the signalproxy --- src/common/signalproxy.cpp | 11 +++++++++-- src/common/syncableobject.cpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/common/signalproxy.cpp b/src/common/signalproxy.cpp index 411c8dae..9078f24a 100644 --- a/src/common/signalproxy.cpp +++ b/src/common/signalproxy.cpp @@ -951,12 +951,19 @@ QString SignalProxy::methodBaseName(const QMetaMethod &method) { QString methodname = QString(method.signature()).section("(", 0, 0); // determine where we have to chop: + int upperCharPos; if(method.methodType() == QMetaMethod::Slot) { // we take evertyhing from the first uppercase char if it's slot - methodname = methodname.mid(methodname.indexOf(QRegExp("[A-Z]"))); + upperCharPos = methodname.indexOf(QRegExp("[A-Z]")); + if(upperCharPos == -1) + return QString(); + methodname = methodname.mid(upperCharPos); } else { // and if it's a signal we discard everything from the last uppercase char - methodname = methodname.left(methodname.lastIndexOf(QRegExp("[A-Z]"))); + upperCharPos = methodname.lastIndexOf(QRegExp("[A-Z]")); + if(upperCharPos == -1) + return QString(); + methodname = methodname.left(upperCharPos); } methodname[0] = methodname[0].toUpper(); diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index ee871b8f..781dd151 100644 --- a/src/common/syncableobject.cpp +++ b/src/common/syncableobject.cpp @@ -20,6 +20,8 @@ #include +#include + #include "syncableobject.h" #include "signalproxy.h" @@ -58,10 +60,15 @@ QVariantMap SyncableObject::toVariantMap() { for(int i = 0; i < meta->methodCount(); i++) { QMetaMethod method = meta->method(i); QString methodname(::methodName(method)); - if(!methodname.startsWith("init") || methodname.startsWith("initSet")) + if(!methodname.startsWith("init") || methodname.startsWith("initSet") || methodname.startsWith("initDone")) continue; - QVariant value = QVariant(QVariant::nameToType(method.typeName())); + QVariant::Type variantType = QVariant::nameToType(method.typeName()); + if(variantType == QVariant::Invalid && !QByteArray(method.typeName()).isEmpty()) { + 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); QMetaObject::invokeMethod(this, methodname.toAscii(), genericvalue); -- 2.20.1