From 5daae2cf6cf4c2fc1569ed3c5c2f25294ac1a57d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Sat, 29 Jun 2019 11:02:51 +0200 Subject: [PATCH] QmlDebug: Queue the socket error and disconnect signals Apparently these can be sent synchronously on trying to send something over the wire. Synchronously handling the signals at that point is dangerous as the rest of the system might be in some transitional state (e.g. just destroying the clients). Fixes: QTCREATORBUG-22640 Change-Id: I21a0c92a6334d401390cf6d92b9b855b83cc6307 Reviewed-by: Christian Stenger --- src/libs/qmldebug/qmldebugconnection.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libs/qmldebug/qmldebugconnection.cpp b/src/libs/qmldebug/qmldebugconnection.cpp index 143277b379b..629360a8bcc 100644 --- a/src/libs/qmldebug/qmldebugconnection.cpp +++ b/src/libs/qmldebug/qmldebugconnection.cpp @@ -35,6 +35,8 @@ #include #include +Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError) + namespace QmlDebug { const int protocolVersion = 1; @@ -244,6 +246,11 @@ void QmlDebugConnection::protocolReadyRead() QmlDebugConnection::QmlDebugConnection(QObject *parent) : QObject(parent), d_ptr(new QmlDebugConnectionPrivate) { + static const int metaTypes[] = { + qRegisterMetaType(), + qRegisterMetaType() + }; + Q_UNUSED(metaTypes); } QmlDebugConnection::~QmlDebugConnection() @@ -343,9 +350,10 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) this, [this](QAbstractSocket::SocketError error) { emit logError(socketErrorToString(error)); socketDisconnected(); - }); + }, Qt::QueuedConnection); connect(socket, &QAbstractSocket::connected, this, &QmlDebugConnection::socketConnected); - connect(socket, &QAbstractSocket::disconnected, this, &QmlDebugConnection::socketDisconnected); + connect(socket, &QAbstractSocket::disconnected, this, &QmlDebugConnection::socketDisconnected, + Qt::QueuedConnection); socket->connectToHost(hostName.isEmpty() ? QString("localhost") : hostName, port); } @@ -376,13 +384,14 @@ void QmlDebugConnection::newConnection() QObject::connect(d->protocol, &QPacketProtocol::readyRead, this, &QmlDebugConnection::protocolReadyRead); - connect(socket, &QLocalSocket::disconnected, this, &QmlDebugConnection::socketDisconnected); + connect(socket, &QLocalSocket::disconnected, this, &QmlDebugConnection::socketDisconnected, + Qt::QueuedConnection); connect(socket, QOverload::of(&QLocalSocket::error), this, [this](QLocalSocket::LocalSocketError error) { emit logError(socketErrorToString(static_cast(error))); socketDisconnected(); - }); + }, Qt::QueuedConnection); connect(socket, &QLocalSocket::stateChanged, this, [this](QLocalSocket::LocalSocketState state) {