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
parent
b39c1a32b5
commit
90c6d44512
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue