diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp index 86fe261f09906c70930c7fdcf25da764617537b0..052655309a3e2668df9390780e8cd4c42efbf13a 100644 --- a/src/libs/qmldebug/qmldebugclient.cpp +++ b/src/libs/qmldebug/qmldebugclient.cpp @@ -68,34 +68,36 @@ public: void flush(); }; -QString QmlDebugConnection::socketStateToString(QAbstractSocket::SocketState state) +static QString socketStateToString(QAbstractSocket::SocketState state) { switch (state) { case QAbstractSocket::UnconnectedState: - return tr("Network connection dropped"); + return QmlDebugConnection::tr("Network connection dropped"); case QAbstractSocket::HostLookupState: - return tr("Resolving host"); + return QmlDebugConnection::tr("Resolving host"); case QAbstractSocket::ConnectingState: - return tr("Establishing network connection ..."); + return QmlDebugConnection::tr("Establishing network connection ..."); case QAbstractSocket::ConnectedState: - return tr("Network connection established"); + return QmlDebugConnection::tr("Network connection established"); case QAbstractSocket::ClosingState: - return tr("Network connection closing"); + return QmlDebugConnection::tr("Network connection closing"); case QAbstractSocket::BoundState: - return tr("Socket state changed to BoundState. This should not happen!"); + return QmlDebugConnection::tr("Socket state changed to BoundState. " + "This should not happen!"); case QAbstractSocket::ListeningState: - return tr("Socket state changed to ListeningState. This should not happen!"); + return QmlDebugConnection::tr("Socket state changed to ListeningState. " + "This should not happen!"); default: - return tr("Unknown state %1").arg(state); + return QmlDebugConnection::tr("Unknown state %1").arg(state); } } -QString QmlDebugConnection::socketErrorToString(QAbstractSocket::SocketError error) +static QString socketErrorToString(QAbstractSocket::SocketError error) { if (error == QAbstractSocket::RemoteHostClosedError) { - return tr("Error: Remote host closed the connection"); + return QmlDebugConnection::tr("Error: Remote host closed the connection"); } else { - return tr("Error: Unknown socket error %1").arg(error); + return QmlDebugConnection::tr("Error: Unknown socket error %1").arg(error); } } @@ -136,6 +138,8 @@ void QmlDebugConnection::socketDisconnected() for (; iter != d->plugins.end(); ++iter) iter.value()->stateChanged(QmlDebugClient::NotConnected); emit disconnected(); + } else if (d->device) { + emit connectionFailed(); } delete d->protocol; d->protocol = 0; @@ -365,9 +369,16 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) d->protocol = new QPacketProtocol(socket, this); QObject::connect(d->protocol, &QPacketProtocol::readyRead, this, &QmlDebugConnection::protocolReadyRead); - connect(socket, &QAbstractSocket::stateChanged, this, &QmlDebugConnection::socketStateChanged); + connect(socket, &QAbstractSocket::stateChanged, + this, [this](QAbstractSocket::SocketState state) { + emit logStateChange(socketStateToString(state)); + }); + connect(socket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)> - (&QAbstractSocket::error), this, &QmlDebugConnection::socketError); + (&QAbstractSocket::error), this, [this](QAbstractSocket::SocketError error) { + emit logError(socketErrorToString(error)); + socketDisconnected(); + }); connect(socket, &QAbstractSocket::connected, this, &QmlDebugConnection::socketConnected); connect(socket, &QAbstractSocket::disconnected, this, &QmlDebugConnection::socketDisconnected); socket->connectToHost(hostName, port); @@ -385,7 +396,7 @@ void QmlDebugConnection::startLocalServer(const QString &fileName) connect(d->server, &QLocalServer::newConnection, this, &QmlDebugConnection::newConnection, Qt::QueuedConnection); if (!d->server->listen(fileName)) - emit socketError(QAbstractSocket::UnknownSocketError); + emit connectionFailed(); } void QmlDebugConnection::newConnection() @@ -403,13 +414,14 @@ void QmlDebugConnection::newConnection() connect(socket, &QLocalSocket::disconnected, this, &QmlDebugConnection::socketDisconnected); connect(socket, static_cast<void (QLocalSocket::*)(QLocalSocket::LocalSocketError)> - (&QLocalSocket::error), this, [this](QLocalSocket::LocalSocketError error) { - socketError(static_cast<QAbstractSocket::SocketError>(error)); + (&QLocalSocket::error), this, [this, d](QLocalSocket::LocalSocketError error) { + logError(socketErrorToString(static_cast<QAbstractSocket::SocketError>(error))); + socketDisconnected(); }); connect(socket, &QLocalSocket::stateChanged, this, [this](QLocalSocket::LocalSocketState state) { - socketStateChanged(static_cast<QAbstractSocket::SocketState>(state)); + logStateChange(socketStateToString(static_cast<QAbstractSocket::SocketState>(state))); }); socketConnected(); diff --git a/src/libs/qmldebug/qmldebugclient.h b/src/libs/qmldebug/qmldebugclient.h index c8d03d5678749d6d126e432b7bfe2dfd6038abbe..2e485ecc1ab48ac725ec529fbb43e2f14df7dba0 100644 --- a/src/libs/qmldebug/qmldebugclient.h +++ b/src/libs/qmldebug/qmldebugclient.h @@ -61,14 +61,13 @@ public: float serviceVersion(const QString &serviceName) const; bool sendMessage(const QString &name, const QByteArray &message); - static QString socketStateToString(QAbstractSocket::SocketState state); - static QString socketErrorToString(QAbstractSocket::SocketError error); - signals: void connected(); void disconnected(); - void socketError(QAbstractSocket::SocketError error); - void socketStateChanged(QAbstractSocket::SocketState state); + void connectionFailed(); + + void logError(const QString &error); + void logStateChange(const QString &state); private: void newConnection(); diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index 26a6661a8bfd28beafac9e86174ff9d8875d4e9f..c6961ad62d360bb4bc79bae78277c54c2923cd78 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -289,10 +289,13 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin connect(&d->connectionTimer, &QTimer::timeout, this, &QmlEngine::checkConnectionState); - connect(d->connection, &QmlDebugConnection::socketStateChanged, - this, &QmlEngine::connectionStateChanged); - connect(d->connection, &QmlDebugConnection::socketError, - this, &QmlEngine::connectionErrorOccurred); + connect(d->connection, &QmlDebugConnection::logStateChange, + this, &QmlEngine::showConnectionStateMessage); + connect(d->connection, &QmlDebugConnection::logError, this, + [this](const QString &error) { showMessage("QML Debugger: " + error, StatusBar); }); + + connect(d->connection, &QmlDebugConnection::connectionFailed, + this, &QmlEngine::connectionFailed); connect(d->connection, &QmlDebugConnection::connected, &d->connectionTimer, &QTimer::stop); connect(d->connection, &QmlDebugConnection::connected, @@ -1200,13 +1203,10 @@ bool QmlEnginePrivate::canEvaluateScript(const QString &script) return interpreter.canEvaluate(); } -void QmlEngine::connectionErrorOccurred(QAbstractSocket::SocketError error) +void QmlEngine::connectionFailed() { // this is only an error if we are already connected and something goes wrong. if (isConnected()) { - if (error == QAbstractSocket::RemoteHostClosedError) - showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar); - if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits notifyInferiorSpontaneousStop(); notifyInferiorIll(); @@ -1217,11 +1217,6 @@ void QmlEngine::connectionErrorOccurred(QAbstractSocket::SocketError error) } } -void QmlEngine::connectionStateChanged(QAbstractSocket::SocketState socketState) -{ - showConnectionStateMessage(QmlDebugConnection::socketStateToString(socketState)); -} - void QmlEngine::checkConnectionState() { if (!isConnected()) { diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h index ab469638fa2b4450244310ed60146b9a91dbe05b..2ce3efd73e032057fd0a139481d033e867674690 100644 --- a/src/plugins/debugger/qml/qmlengine.h +++ b/src/plugins/debugger/qml/qmlengine.h @@ -133,8 +133,7 @@ private: void startApplicationLauncher(); void stopApplicationLauncher(); - void connectionErrorOccurred(QAbstractSocket::SocketError socketError); - void connectionStateChanged(QAbstractSocket::SocketState socketState); + void connectionFailed(); void checkConnectionState(); void showConnectionStateMessage(const QString &message); diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp index db488bee76179d9ceb08593fc748f75a3c209c41..dd9a3027d2ead8edbb30610469b69979660f82a4 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp @@ -179,10 +179,13 @@ void QmlProfilerClientManager::createConnection() this, &QmlProfilerClientManager::qmlDebugConnectionOpened); connect(d->connection, &QmlDebug::QmlDebugConnection::disconnected, this, &QmlProfilerClientManager::qmlDebugConnectionClosed); - connect(d->connection, &QmlDebug::QmlDebugConnection::socketError, - this, &QmlProfilerClientManager::qmlDebugConnectionError); - connect(d->connection, &QmlDebug::QmlDebugConnection::socketStateChanged, - this, &QmlProfilerClientManager::qmlDebugConnectionStateChanged); + connect(d->connection, &QmlDebug::QmlDebugConnection::connectionFailed, + this, &QmlProfilerClientManager::qmlDebugConnectionFailed); + + connect(d->connection, &QmlDebug::QmlDebugConnection::logError, + this, &QmlProfilerClientManager::logState); + connect(d->connection, &QmlDebug::QmlDebugConnection::logStateChange, + this, &QmlProfilerClientManager::logState); } void QmlProfilerClientManager::retryConnect() @@ -294,9 +297,8 @@ void QmlProfilerClientManager::qmlDebugConnectionClosed() emit connectionClosed(); } -void QmlProfilerClientManager::qmlDebugConnectionError(QAbstractSocket::SocketError error) +void QmlProfilerClientManager::qmlDebugConnectionFailed() { - logState(QmlDebug::QmlDebugConnection::socketErrorToString(error)); if (d->connection->isConnected()) { disconnectClient(); emit connectionClosed(); @@ -305,11 +307,6 @@ void QmlProfilerClientManager::qmlDebugConnectionError(QAbstractSocket::SocketEr } } -void QmlProfilerClientManager::qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state) -{ - logState(QmlDebug::QmlDebugConnection::socketStateToString(state)); -} - void QmlProfilerClientManager::logState(const QString &msg) { QmlProfilerTool::logState(QLatin1String("QML Profiler: ") + msg); diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.h b/src/plugins/qmlprofiler/qmlprofilerclientmanager.h index 1b4b71ed2c54e718d7ce3f62184930cb95662849..c4a478d9c795645b0f4c7623b722d9b8b6fcb01b 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.h @@ -72,8 +72,8 @@ private slots: void tryToConnect(); void qmlDebugConnectionOpened(); void qmlDebugConnectionClosed(); - void qmlDebugConnectionError(QAbstractSocket::SocketError error); - void qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state); + void qmlDebugConnectionFailed(); + void logState(const QString &); void qmlComplete(qint64 maximumTime);