diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp index 2f5b7976cd7..126830ba13f 100644 --- a/src/libs/qmldebug/qmldebugclient.cpp +++ b/src/libs/qmldebug/qmldebugclient.cpp @@ -334,6 +334,15 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) socket->connectToHost(hostName, port); } +QAbstractSocket::SocketState QmlDebugConnection::socketState() const +{ + // TODO: when merging into master, add clause for local socket + if (QAbstractSocket *socket = qobject_cast(d->device)) + return socket->state(); + else + return QAbstractSocket::UnconnectedState; +} + // QmlDebugClientPrivate::QmlDebugClientPrivate() diff --git a/src/libs/qmldebug/qmldebugclient.h b/src/libs/qmldebug/qmldebugclient.h index 01c871ba09c..fdee2f290e9 100644 --- a/src/libs/qmldebug/qmldebugclient.h +++ b/src/libs/qmldebug/qmldebugclient.h @@ -55,6 +55,7 @@ public: ~QmlDebugConnection(); void connectToHost(const QString &hostName, quint16 port); + QAbstractSocket::SocketState socketState() const; bool isOpen() const; bool isConnecting() const; diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp index a355955f5bd..753a389d33c 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp @@ -242,6 +242,17 @@ void QmlProfilerClientManager::tryToConnect() if (d->connection && d->connection->isOpen()) { d->connectionTimer.stop(); d->connectionAttempts = 0; + } else if (d->connection && + d->connection->socketState() != QAbstractSocket::ConnectedState) { + // Replace the connection after trying for some time. On some operating systems (OSX) the + // very first connection to a TCP server takes a very long time to get established. + + // delete directly here, so that any pending events aren't delivered. We don't want the + // connection first to be established and then torn down again. + delete d->connection; + d->connection = 0; + connectClient(d->tcpPort); + connectToClient(); } else if (d->connectionAttempts == 50) { d->connectionTimer.stop(); d->connectionAttempts = 0;