diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-03-20 19:27:02 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-21 18:55:51 +0100 |
commit | 22d621dd99417be289b311e3fea5a24f385596fb (patch) | |
tree | 8fd506e6c57a9cfd1efeccb0305b19dee0879e07 /src/corelib/kernel/qmetaobjectbuilder.cpp | |
parent | b8d71ed60ba57142237555edb97d4cc7d3675b5c (diff) |
QMetaMethod::typeName() should return "void" if the return type is void
QMetaMethod::typeName() is documented to return an empty string if
the return type is void. But after the introduction of
QMetaType::UnknownType (where void was made a distinct type),
returning an empty string causes the idiom
QMetaType::type(method.typeName())
to break; the result will be QMetaType::UnknownType rather than
the expected QMetaType::Void for methods that return void.
New code should use the new function QMetaMethod::returnType()
instead, but it would be good if existing code still did the right
thing.
The consequence of returning "void" instead of an empty string is
that it breaks existing logic that uses the typeName() length to
determine whether a method returns void. But we judge this as the
lesser of the two evils; it's better to have a typeName() function
that is consistent and keeps the QMetaType::type(method.typeName())
idiom working, than to force the typeName() inconsistency for void
only to keep code that does "strlen(method.typeName()) == 0"
working.
The places in Qt that were relying on a zero-length typeName()
(testlib, dbus, declarative) have already been changed to use
returnType().
Also adapt QMetaObjectBuilder, which is internal API.
Change-Id: I70249174029811c5b5d2a08c24b6db33b3723d19
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qmetaobjectbuilder.cpp')
-rw-r--r-- | src/corelib/kernel/qmetaobjectbuilder.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 13cd1a684a..e282a22f70 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -96,7 +96,7 @@ public: QMetaMethodBuilderPrivate (QMetaMethod::MethodType _methodType, const QByteArray& _signature, - const QByteArray& _returnType = QByteArray(), + const QByteArray& _returnType = QByteArray("void"), QMetaMethod::Access _access = QMetaMethod::Public, int _revision = 0) : signature(QMetaObject::normalizedSignature(_signature.constData())), @@ -435,8 +435,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature) \a signature and \a returnType. Returns an object that can be used to adjust the other attributes of the method. The \a signature and \a returnType will be normalized before they are added to - the class. If \a returnType is empty, then it indicates that - the method has \c{void} as its return type. + the class. \sa method(), methodCount(), removeMethod(), indexOfMethod() */ @@ -507,7 +506,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) { int index = d->methods.size(); d->methods.append(QMetaMethodBuilderPrivate - (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected)); + (QMetaMethod::Signal, signature, QByteArray("void"), QMetaMethod::Protected)); return QMetaMethodBuilder(this, index); } @@ -523,7 +522,8 @@ QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature) { int index = d->constructors.size(); - d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature)); + d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature, + /*returnType=*/QByteArray())); return QMetaMethodBuilder(this, -(index + 1)); } |