diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2011-05-12 17:23:14 +1000 |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-05-13 10:42:06 +1000 |
commit | d9119535a2e3fcb977998ab1f7006f8a15b5a140 (patch) | |
tree | f8b55075e929f99543e4325f519987fcd6218061 | |
parent | e40443f7dfaa77e1295390385ef76f9b4e87c59b (diff) |
Make error checking in QSignalSpy consistent
QSignalSpy's constructor failed gracefully for some problems with the
parameters, but not for null parameters, for which there was only a
Q_ASSERT. This commit makes the handling of null parameters consistent
with the handling of other errors -- output a meaningful error message
with qWarning() and return, so that isValid() will subsequently return
false.
Change-Id: I7f5677a4c10185e30403ce3e12a022de8c13bc1c
Task-number: QTBUG-14283
Reviewed-by: Rohan McGovern
-rw-r--r-- | src/testlib/qsignalspy.h | 11 | ||||
-rw-r--r-- | src/testlib/qsignalspy.qdoc | 6 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h index b0b48c5025..fce5aad56a 100644 --- a/src/testlib/qsignalspy.h +++ b/src/testlib/qsignalspy.h @@ -68,8 +68,15 @@ public: #else static const int memberOffset = QObject::staticMetaObject.methodCount(); #endif - Q_ASSERT(obj); - Q_ASSERT(aSignal); + if (!obj) { + qWarning("QSignalSpy: Cannot spy on a null object"); + return; + } + + if (!aSignal) { + qWarning("QSignalSpy: Null signal name is not valid"); + return; + } if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE) { qWarning("QSignalSpy: Not a valid signal, use the SIGNAL macro"); diff --git a/src/testlib/qsignalspy.qdoc b/src/testlib/qsignalspy.qdoc index 0c22868852..83dcccede2 100644 --- a/src/testlib/qsignalspy.qdoc +++ b/src/testlib/qsignalspy.qdoc @@ -62,7 +62,11 @@ /*! \fn QSignalSpy::QSignalSpy(QObject *object, const char *signal) Constructs a new QSignalSpy that listens for emissions of the \a signal - from the QObject \a object. Neither \a signal nor \a object can be null. + from the QObject \a object. If QSignalSpy is not able to listen for a + valid signal (for example, because \a object is null or \a signal does + not denote a valid signal of \a object), an explanatory warning message + will be output using qWarning() and subsequent calls to \c isValid() will + return false. Example: \snippet doc/src/snippets/code/doc_src_qsignalspy.cpp 4 |