From ee3c8ce7d2afe381219459abe477f663856be073 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 16 Feb 2022 12:40:20 +0100 Subject: [PATCH] Clean up preferred connection if it vanishes --- libnymea-app/connection/nymeaconnection.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libnymea-app/connection/nymeaconnection.cpp b/libnymea-app/connection/nymeaconnection.cpp index 7533afca..64e22ddc 100644 --- a/libnymea-app/connection/nymeaconnection.cpp +++ b/libnymea-app/connection/nymeaconnection.cpp @@ -132,6 +132,8 @@ void NymeaConnection::setCurrentHost(NymeaHost *host) return; } + m_preferredConnection = nullptr; + if (m_currentTransport) { m_currentTransport = nullptr; emit currentConnectionChanged(); @@ -459,6 +461,10 @@ void NymeaConnection::connectToHost(NymeaHost *nymeaHost, Connection *connection if (nymeaHost->connections()->find(connection->url())) { qCInfo(dcNymeaConnection()) << "Setting preferred connection to" << connection->url(); m_preferredConnection = connection; + // Unset the preferred connection when it is removed + connect(connection, &Connection::destroyed, this, [=](){ + m_preferredConnection = nullptr; + }); } else { qCWarning(dcNymeaConnection()) << "Connection" << connection << "is not a candidate for" << nymeaHost->name() << "Not setting preferred connection."; }