summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2014-06-11 11:15:59 +0200
committerMitch Curtis <mitch.curtis@digia.com>2014-06-20 21:51:51 +0200
commitdaa56f1b4e784d6497ae4fdeaa664f3a1a7b5143 (patch)
tree2d7df35ac521ae749297237cd91a9e3d915a4b2d /src
parentf3e86a8cc87754d7efbd33c15f61d554ce3160f0 (diff)
Suggest candidates when non-existent method passed to invokeMethod().
QMetaObject::invokeMethod: No such method Object::someMethod(SomeType) becomes: QMetaObject::invokeMethod: No such method Object::someMethod(SomeType) Candidates are: someMethod(SomeOtherType) someMethod(YetAnotherType) Change-Id: I3566bca64423e2f8150d0d544fb4e35a5262b19e Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index accefb1ec4..cb63718680 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -1339,6 +1339,27 @@ QByteArray QMetaObject::normalizedSignature(const char *method)
enum { MaximumParamCount = 11 }; // up to 10 arguments + 1 return value
/*!
+ Returns the signatures of all methods whose name matches \a nonExistentMember,
+ or an empty QByteArray if there are no matches.
+*/
+static inline QByteArray findMethodCandidates(const QMetaObject *metaObject, const char *nonExistentMember)
+{
+ QByteArray candidateMessage;
+ // Prevent full string comparison in every iteration.
+ const QByteArray memberByteArray = nonExistentMember;
+ for (int i = 0; i < metaObject->methodCount(); ++i) {
+ const QMetaMethod method = metaObject->method(i);
+ if (method.name() == memberByteArray)
+ candidateMessage.append(" " + method.methodSignature() + '\n');
+ }
+ if (!candidateMessage.isEmpty()) {
+ candidateMessage.prepend("\nCandidates are:\n");
+ candidateMessage.chop(1);
+ }
+ return candidateMessage;
+}
+
+/*!
Invokes the \a member (a signal or a slot name) on the object \a
obj. Returns \c true if the member could be invoked. Returns \c false
if there is no such member or the parameters did not match.
@@ -1455,8 +1476,9 @@ bool QMetaObject::invokeMethod(QObject *obj,
}
if (idx < 0 || idx >= meta->methodCount()) {
- qWarning("QMetaObject::invokeMethod: No such method %s::%s",
- meta->className(), sig.constData());
+ // This method doesn't belong to us; print out a nice warning with candidates.
+ qWarning("QMetaObject::invokeMethod: No such method %s::%s%s",
+ meta->className(), sig.constData(), findMethodCandidates(meta, member).constData());
return false;
}
QMetaMethod method = meta->method(idx);