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>
bb10
Kent Hansen 2012-04-22 14:30:32 +02:00 committed by Qt by Nokia
parent b39c1a32b5
commit 90c6d44512
2 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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);