diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2013-09-25 18:15:33 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-06 19:21:19 +0200 |
commit | c14977cc806227bc546043c0d16ede21b856e830 (patch) | |
tree | 09e82bf0b6bddbfce77dc1332215aaa46c6aa1a7 /src/imports | |
parent | 590fa9441c01ec1acf987091929a4d07d744b72b (diff) |
Fix QDeclarativeBluetoothSocket stringData property
Task-number: QTBUG-31729
Change-Id: Idd820e57b72c2293c999bdc0a578d1e8f8e5471b
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/bluetooth/qdeclarativebluetoothsocket.cpp | 34 | ||||
-rw-r--r-- | src/imports/bluetooth/qdeclarativebluetoothsocket_p.h | 2 |
2 files changed, 9 insertions, 27 deletions
diff --git a/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp b/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp index 54a4ef8e..c94807a4 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp +++ b/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp @@ -118,8 +118,6 @@ public: QObject::connect(m_socket, SIGNAL(error(QBluetoothSocket::SocketError)), m_dbs, SLOT(socket_error(QBluetoothSocket::SocketError))); QObject::connect(m_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), m_dbs, SLOT(socket_state(QBluetoothSocket::SocketState))); QObject::connect(m_socket, SIGNAL(readyRead()), m_dbs, SLOT(socket_readyRead())); - - m_stream = new QDataStream(m_socket); } QDeclarativeBluetoothSocket *m_dbs; @@ -129,8 +127,6 @@ public: QDeclarativeBluetoothSocket::SocketState m_state; bool m_componentCompleted; bool m_connected; - QDataStream *m_stream; - }; QDeclarativeBluetoothSocket::QDeclarativeBluetoothSocket(QObject *parent) : @@ -160,9 +156,6 @@ QDeclarativeBluetoothSocket::QDeclarativeBluetoothSocket(QBluetoothSocket *socke QObject::connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socket_error(QBluetoothSocket::SocketError))); QObject::connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), this, SLOT(socket_state(QBluetoothSocket::SocketState))); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(socket_readyRead())); - - d->m_stream = new QDataStream(socket); - } @@ -312,15 +305,6 @@ QDeclarativeBluetoothSocket::SocketState QDeclarativeBluetoothSocket::state() co return d->m_state; } -/*! - \qmlsignal BluetoothSocket::dataAvailable() - - This signal indicates the arrival of new data. It is emitted each time the socket has new - data available. The data can be read from the property stringData. - \sa stringData - \sa sendStringData - */ - void QDeclarativeBluetoothSocket::socket_readyRead() { emit dataAvailable(); @@ -344,30 +328,30 @@ QString QDeclarativeBluetoothSocket::stringData() return QString(); QString data; - *d->m_stream >> data; + while (d->m_socket->canReadLine()) { + QByteArray line = d->m_socket->readLine(); + data += QString::fromUtf8(line.constData(), line.length()); + } + return data; } /*! - \qmlmethod BluetoothSocket::sendStringData(data) - This method transmits the string data passed with "data" to the remote device. If excessive amounts of data are sent, the function may block sending. \sa dataAvailable \sa stringData */ -void QDeclarativeBluetoothSocket::sendStringData(QString data) +void QDeclarativeBluetoothSocket::sendStringData(const QString &data) { if (!d->m_connected || !d->m_socket){ qWarning() << "Writing data to unconnected socket"; return; } - QByteArray b; - QDataStream s(&b, QIODevice::WriteOnly); - s << data; - d->m_socket->write(b); + QByteArray text = data.toUtf8() + '\n'; + d->m_socket->write(text); } void QDeclarativeBluetoothSocket::newSocket(QBluetoothSocket *socket, QDeclarativeBluetoothService *service) @@ -388,8 +372,6 @@ void QDeclarativeBluetoothSocket::newSocket(QBluetoothSocket *socket, QDeclarati QObject::connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), this, SLOT(socket_state(QBluetoothSocket::SocketState))); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(socket_readyRead())); - d->m_stream = new QDataStream(socket); - socket_state(socket->state()); emit connectedChanged(); diff --git a/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h b/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h index ec63a829..cb6255b6 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h +++ b/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h @@ -120,7 +120,7 @@ signals: public slots: void setService(QDeclarativeBluetoothService *service); void setConnected(bool connected); - void sendStringData(QString data); + void sendStringData(const QString& data); private slots: void socket_connected(); |