diff --git a/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp b/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp
index e11eadfbafaf3672584608f6d3773453aa21bd88..f12eaf6937ef6dcd625fe7d6e1130da9cba3e4a9 100644
--- a/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp
+++ b/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp
@@ -246,6 +246,14 @@ void QDeclarativeDebugConnection::close()
     }
 }
 
+bool QDeclarativeDebugConnection::waitForConnected(int msecs)
+{
+    QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device);
+    if (socket)
+        return socket->waitForConnected(msecs);
+    return false;
+}
+
 // For ease of refactoring we use QAbstractSocket's states even if we're actually using a OstChannel underneath
 // since serial ports have a subset of the socket states afaics
 QAbstractSocket::SocketState QDeclarativeDebugConnection::state() const
@@ -350,7 +358,7 @@ QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name,
 
 QDeclarativeDebugClient::~QDeclarativeDebugClient()
 {
-    Q_D(QDeclarativeDebugClient);
+    Q_D(const QDeclarativeDebugClient);
     if (d->connection && d->connection->d) {
         d->connection->d->plugins.remove(d->name);
         d->connection->d->advertisePlugins();
diff --git a/src/libs/qmljsdebugclient/qdeclarativedebugclient.h b/src/libs/qmljsdebugclient/qdeclarativedebugclient.h
index 170ee51acca2213ea0d3dc855031a437c7ea42e5..fe118de535e2f9a5734ef50a660fa919bb100e86 100644
--- a/src/libs/qmljsdebugclient/qdeclarativedebugclient.h
+++ b/src/libs/qmljsdebugclient/qdeclarativedebugclient.h
@@ -41,7 +41,7 @@ class QDeclarativeDebugConnectionPrivate;
 class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugConnection : public QIODevice
 {
     Q_OBJECT
-
+    Q_DISABLE_COPY(QDeclarativeDebugConnection)
 public:
     QDeclarativeDebugConnection(QObject * = 0);
     ~QDeclarativeDebugConnection();
@@ -55,13 +55,14 @@ public:
     void flush();
     bool isSequential() const;
     void close();
+    bool waitForConnected(int msecs = 30000);
 
 signals:
     void connected();
     void stateChanged(QAbstractSocket::SocketState socketState);
     void error(QAbstractSocket::SocketError socketError);
 
-private:
+protected:
     qint64 readData(char *data, qint64 maxSize);
     qint64 writeData(const char *data, qint64 maxSize);
 
@@ -76,6 +77,7 @@ class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugClient : public QObject
 {
     Q_OBJECT
     Q_DECLARE_PRIVATE(QDeclarativeDebugClient)
+    Q_DISABLE_COPY(QDeclarativeDebugClient)
 
 public:
     enum Status { NotConnected, Unavailable, Enabled };
diff --git a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp
index 9dab5852177b04d0d3fbbb053cec5e2c739e82b5..db3f4a778109d3f9b87d0f40fac7874863d44880 100644
--- a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp
+++ b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp
@@ -39,7 +39,6 @@ class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient
 {
 public:
     QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p);
-    ~QDeclarativeEngineDebugClient();
 
 protected:
     virtual void statusChanged(Status status);
@@ -88,10 +87,6 @@ QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugCo
 {
 }
 
-QDeclarativeEngineDebugClient::~QDeclarativeEngineDebugClient()
-{
-}
-
 void QDeclarativeEngineDebugClient::statusChanged(Status status)
 {
     if (priv)
@@ -445,7 +440,9 @@ QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *cl
 {
 }
 
-QDeclarativeEngineDebug::~QDeclarativeEngineDebug() { }
+QDeclarativeEngineDebug::~QDeclarativeEngineDebug()
+{
+}
 
 QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const
 {
diff --git a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h
index 51d3120ad333f9653b40fb0dd91449beebca7f71..ed941a5e3b56e64b6ca4325d309b607166d6715a 100644
--- a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h
+++ b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h
@@ -29,8 +29,8 @@
 **
 **************************************************************************/
 
-#ifndef QDECLARATIVEDEBUG_H
-#define QDECLARATIVEDEBUG_H
+#ifndef QDECLARATIVEENGINEDEBUG_H
+#define QDECLARATIVEENGINEDEBUG_H
 
 #include "qmljsdebugclient_global.h"
 #include <QtCore/qobject.h>
@@ -368,4 +368,4 @@ Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugObjectReference)
 Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugContextReference)
 Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugPropertyReference)
 
-#endif // QDECLARATIVEDEBUG_H
+#endif // QDECLARATIVEENGINEDEBUG_H
diff --git a/src/libs/qmljsdebugclient/qpacketprotocol.cpp b/src/libs/qmljsdebugclient/qpacketprotocol.cpp
index 2bae0758ab4b1809f920fb3a8b7e4f3f59fdd696..d19d666d05dc57d4e49270847fc7e5e17d5b7120 100644
--- a/src/libs/qmljsdebugclient/qpacketprotocol.cpp
+++ b/src/libs/qmljsdebugclient/qpacketprotocol.cpp
@@ -31,7 +31,8 @@
 
 #include "qpacketprotocol.h"
 
-#include <QtCore/QBuffer>
+#include <QtCore/qbuffer.h>
+#include <QtCore/qelapsedtimer.h>
 
 namespace QmlJsDebugClient {
 
@@ -105,7 +106,7 @@ class QPacketProtocolPrivate : public QObject
 public:
     QPacketProtocolPrivate(QPacketProtocol *parent, QIODevice *_dev)
         : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE),
-          dev(_dev)
+          waitingForPacket(false), dev(_dev)
     {
         Q_ASSERT(4 == sizeof(qint32));
 
@@ -189,6 +190,7 @@ public Q_SLOTS:
                     inProgressSize = -1;
                     inProgress.clear();
 
+                    waitingForPacket = false;
                     emit readyRead();
                 } else
                     return;
@@ -202,14 +204,15 @@ public:
     QByteArray inProgress;
     qint32 inProgressSize;
     qint32 maxPacketSize;
-    QIODevice * dev;
+    bool waitingForPacket;
+    QIODevice *dev;
 };
 
 /*!
   Construct a QPacketProtocol instance that works on \a dev with the
   specified \a parent.
  */
-QPacketProtocol::QPacketProtocol(QIODevice * dev, QObject * parent)
+QPacketProtocol::QPacketProtocol(QIODevice *dev, QObject *parent)
     : QObject(parent), d(new QPacketProtocolPrivate(this, dev))
 {
     Q_ASSERT(dev);
@@ -313,10 +316,53 @@ QPacket QPacketProtocol::read()
     return rv;
 }
 
+
+/*
+   Returns the difference between msecs and elapsed. If msecs is -1,
+   however, -1 is returned.
+*/
+static int qt_timeout_value(int msecs, int elapsed)
+{
+    if (msecs == -1)
+        return -1;
+
+    int timeout = msecs - elapsed;
+    return timeout < 0 ? 0 : timeout;
+}
+
+/*!
+  This function locks until a new packet is available for reading and the
+  \l{QIODevice::}{readyRead()} signal has been emitted. The function
+  will timeout after \a msecs milliseconds; the default timeout is
+  30000 milliseconds.
+
+  The function returns true if the readyRead() signal is emitted and
+  there is new data available for reading; otherwise it returns false
+  (if an error occurred or the operation timed out).
+  */
+
+bool QPacketProtocol::waitForReadyRead(int msecs)
+{
+    if (!d->packets.isEmpty())
+        return true;
+
+    QElapsedTimer stopWatch;
+    stopWatch.start();
+
+    d->waitingForPacket = true;
+    do {
+        if (!d->dev->waitForReadyRead(msecs))
+            return false;
+        if (!d->waitingForPacket)
+            return true;
+        msecs = qt_timeout_value(msecs, stopWatch.elapsed());
+    } while (true);
+}
+
 /*!
   Return the QIODevice passed to the QPacketProtocol constructor.
 */
-QIODevice * QPacketProtocol::device()
+QIODevice *QPacketProtocol::device()
 {
     return d->dev;
 }
@@ -396,6 +442,7 @@ QPacket::QPacket()
     buf = new QBuffer(&b);
     buf->open(QIODevice::WriteOnly);
     setDevice(buf);
+    setVersion(QDataStream::Qt_4_7);
 }
 
 /*!
@@ -440,6 +487,14 @@ bool QPacket::isEmpty() const
     return b.isEmpty();
 }
 
+/*!
+  Returns raw packet data.
+  */
+QByteArray QPacket::data() const
+{
+    return b;
+}
+
 /*!
   Clears data in the packet.  This is useful for reusing one writable packet.
   For example
@@ -471,7 +526,7 @@ void QPacket::clear()
 
   \internal
   */
-QPacketAutoSend::QPacketAutoSend(QPacketProtocol * _p)
+QPacketAutoSend::QPacketAutoSend(QPacketProtocol *_p)
     : QPacket(), p(_p)
 {
 }
diff --git a/src/libs/qmljsdebugclient/qpacketprotocol.h b/src/libs/qmljsdebugclient/qpacketprotocol.h
index 05bc28f8003c0b4964fb7d20cba843e37bef6ea4..2a75f2b365ee4cb5db9fd81da5912a40ba9c939c 100644
--- a/src/libs/qmljsdebugclient/qpacketprotocol.h
+++ b/src/libs/qmljsdebugclient/qpacketprotocol.h
@@ -64,6 +64,8 @@ public:
     qint64 packetsAvailable() const;
     QPacket read();
 
+    bool waitForReadyRead(int msecs = 3000);
+
     void clear();
 
     QIODevice *device();
@@ -87,6 +89,7 @@ public:
 
     void clear();
     bool isEmpty() const;
+    QByteArray data() const;
 
 protected:
     friend class QPacketProtocol;