diff --git a/src/plugins/debugger/qml/qmladapter.cpp b/src/plugins/debugger/qml/qmladapter.cpp index 985fc4d981097c13003317ba72555942e508c15d..4c32f3c68a8c30b4d92df21afa1c0cae363c68b7 100644 --- a/src/plugins/debugger/qml/qmladapter.cpp +++ b/src/plugins/debugger/qml/qmladapter.cpp @@ -36,6 +36,8 @@ #include <QtCore/QTimer> #include <QtCore/QDebug> +#include <utils/qtcassert.h> + namespace Debugger { struct QmlAdapterPrivate { @@ -49,6 +51,7 @@ struct QmlAdapterPrivate { int m_connectionAttempts; int m_maxConnectionAttempts; QDeclarativeDebugConnection *m_conn; + QList<QByteArray> sendBuffer; }; QmlAdapterPrivate::QmlAdapterPrivate(DebuggerEngine *engine, QmlAdapter *q) : @@ -133,6 +136,16 @@ bool QmlAdapter::connectToViewer() return true; } +void QmlAdapter::sendMessage(const QByteArray &msg) +{ + if (d->m_qmlClient->status() == QDeclarativeDebugClient::Enabled) { + flushSendBuffer(); + d->m_qmlClient->sendMessage(msg); + } else { + d->sendBuffer.append(msg); + } +} + void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketError) { showConnectionErrorMessage(tr("Error: (%1) %2", "%1=error code, %2=error message") @@ -151,6 +164,9 @@ void QmlAdapter::clientStatusChanged(QDeclarativeDebugClient::Status status) } logServiceStatusChange(serviceName, status); + + if (status == QDeclarativeDebugClient::Enabled) + flushSendBuffer(); } void QmlAdapter::connectionStateChanged() @@ -199,7 +215,7 @@ void QmlAdapter::createDebuggerClient() connect(d->m_qmlClient, SIGNAL(newStatus(QDeclarativeDebugClient::Status)), this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); connect(d->m_engine.data(), SIGNAL(sendMessage(QByteArray)), - d->m_qmlClient, SLOT(slotSendMessage(QByteArray))); + this, SLOT(sendMessage(QByteArray))); connect(d->m_qmlClient, SIGNAL(messageWasReceived(QByteArray)), d->m_engine.data(), SLOT(messageReceived(QByteArray))); @@ -272,4 +288,13 @@ void QmlAdapter::logServiceStatusChange(const QString &service, QDeclarativeDebu } } +void QmlAdapter::flushSendBuffer() +{ + QTC_ASSERT(d->m_qmlClient->status() == QDeclarativeDebugClient::Enabled, return); + foreach (const QByteArray &msg, d->sendBuffer) { + d->m_qmlClient->sendMessage(msg); + } + d->sendBuffer.clear(); +} + } // namespace Debugger diff --git a/src/plugins/debugger/qml/qmladapter.h b/src/plugins/debugger/qml/qmladapter.h index 8cbce25139749d8d04a84d05dbda3899a450f1b6..329faec69a18d5cd7e27ff159f1b21983e16c595 100644 --- a/src/plugins/debugger/qml/qmladapter.h +++ b/src/plugins/debugger/qml/qmladapter.h @@ -84,6 +84,7 @@ signals: void serviceConnectionError(const QString serviceName); private slots: + void sendMessage(const QByteArray &msg); void connectionErrorOccurred(QAbstractSocket::SocketError socketError); void clientStatusChanged(QDeclarativeDebugClient::Status status); void connectionStateChanged(); @@ -94,6 +95,7 @@ private: void createDebuggerClient(); void showConnectionStatusMessage(const QString &message); void showConnectionErrorMessage(const QString &message); + void flushSendBuffer(); private: QScopedPointer<QmlAdapterPrivate> d; diff --git a/src/plugins/debugger/qml/qmldebuggerclient.cpp b/src/plugins/debugger/qml/qmldebuggerclient.cpp index b0953df3004f0a1627e521a0665098ab482ee111..99ebc0019c4f7a1623aee121ce40661a09bc5d03 100644 --- a/src/plugins/debugger/qml/qmldebuggerclient.cpp +++ b/src/plugins/debugger/qml/qmldebuggerclient.cpp @@ -53,10 +53,5 @@ void QmlDebuggerClient::messageReceived(const QByteArray &data) emit messageWasReceived(data); } -void QmlDebuggerClient::slotSendMessage(const QByteArray &message) -{ - QDeclarativeDebugClient::sendMessage(message); -} - } // Internal } // Debugger diff --git a/src/plugins/debugger/qml/qmldebuggerclient.h b/src/plugins/debugger/qml/qmldebuggerclient.h index 271f632a94a80ba00a60701183a7b6568388a140..2345a56d923c1329905184cfcaa885958dab1510 100644 --- a/src/plugins/debugger/qml/qmldebuggerclient.h +++ b/src/plugins/debugger/qml/qmldebuggerclient.h @@ -47,9 +47,6 @@ signals: void newStatus(QDeclarativeDebugClient::Status status); void messageWasReceived(const QByteArray &data); -private Q_SLOTS: - void slotSendMessage(const QByteArray &message); - protected: virtual void statusChanged(Status status); virtual void messageReceived(const QByteArray &data);