summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-04-22 14:30:32 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-01 01:18:03 +0200
commit90c6d445120a4b057c9e75c1f004d203ec715d10 (patch)
tree90201d6e621597d777e917c136069195a7e0c0d6 /src
parentb39c1a32b513b413fcfe055131476880f4b5a20e (diff)
Port QBuffer to QMetaMethod-based connectNotify()
The const char *-based API is deprecated and will be removed in Qt5. Also fix a bug in the disconnectNotify() reimplementation; when all signals are disconnected at once, disconnectNotify() is only called a single time, with an invalid method as argument. Thus, the signal connection count should be set to 0, instead of decremented. Change-Id: Ieee92293777bff87f8b28e56e23ab55d0b8b8101 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qbuffer.cpp19
-rw-r--r--src/corelib/io/qbuffer.h4
2 files changed, 16 insertions, 7 deletions
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index af71af1fc4..dee4295966 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qbuffer.h"
+#include <QtCore/qmetaobject.h>
#include "private/qiodevice_p.h"
QT_BEGIN_NAMESPACE
@@ -459,9 +460,11 @@ qint64 QBuffer::writeData(const char *data, qint64 len)
\reimp
\internal
*/
-void QBuffer::connectNotify(const char *signal)
+void QBuffer::connectNotify(const QMetaMethod &signal)
{
- if (strcmp(signal + 1, "readyRead()") == 0 || strcmp(signal + 1, "bytesWritten(qint64)") == 0)
+ static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);
+ static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);
+ if (signal == readyReadSignal || signal == bytesWrittenSignal)
d_func()->signalConnectionCount++;
}
@@ -469,10 +472,16 @@ void QBuffer::connectNotify(const char *signal)
\reimp
\internal
*/
-void QBuffer::disconnectNotify(const char *signal)
+void QBuffer::disconnectNotify(const QMetaMethod &signal)
{
- if (!signal || strcmp(signal + 1, "readyRead()") == 0 || strcmp(signal + 1, "bytesWritten(qint64)") == 0)
- d_func()->signalConnectionCount--;
+ if (signal.isValid()) {
+ static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead);
+ static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten);
+ if (signal == readyReadSignal || signal == bytesWrittenSignal)
+ d_func()->signalConnectionCount--;
+ } else {
+ d_func()->signalConnectionCount = 0;
+ }
}
#endif
diff --git a/src/corelib/io/qbuffer.h b/src/corelib/io/qbuffer.h
index 8b42363f24..ffbc554ec4 100644
--- a/src/corelib/io/qbuffer.h
+++ b/src/corelib/io/qbuffer.h
@@ -88,8 +88,8 @@ public:
protected:
#ifndef QT_NO_QOBJECT
- void connectNotify(const char*);
- void disconnectNotify(const char*);
+ void connectNotify(const QMetaMethod &);
+ void disconnectNotify(const QMetaMethod &);
#endif
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);