diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp
index cb56f3e47f7c1e4c053c7b27bf5b0723552624fb..4bbfd93b9f6a8529e96ef89337132194fbfb4e6b 100644
--- a/src/plugins/debugger/debuggerruncontrol.cpp
+++ b/src/plugins/debugger/debuggerruncontrol.cpp
@@ -702,6 +702,11 @@ GdbServerPortsGatherer::GdbServerPortsGatherer(RunControl *runControl)
     : RunWorker(runControl)
 {
     setDisplayName("GdbServerPortsGatherer");
+
+    connect(&m_portsGatherer, &DeviceUsedPortsGatherer::error,
+            this, &RunWorker::reportFailure);
+    connect(&m_portsGatherer, &DeviceUsedPortsGatherer::portListReady,
+            this, &GdbServerPortsGatherer::handlePortListReady);
 }
 
 GdbServerPortsGatherer::~GdbServerPortsGatherer()
@@ -711,31 +716,29 @@ GdbServerPortsGatherer::~GdbServerPortsGatherer()
 void GdbServerPortsGatherer::start()
 {
     appendMessage(tr("Checking available ports..."), NormalMessageFormat);
-    connect(&m_portsGatherer, &DeviceUsedPortsGatherer::error, this, [this](const QString &msg) {
-        reportFailure(msg);
-    });
-    connect(&m_portsGatherer, &DeviceUsedPortsGatherer::portListReady, this, [this] {
-        Utils::PortList portList = device()->freePorts();
-        appendMessage(tr("Found %1 free ports").arg(portList.count()), NormalMessageFormat);
-        if (m_useGdbServer) {
-            m_gdbServerPort = m_portsGatherer.getNextFreePort(&portList);
-            if (!m_gdbServerPort.isValid()) {
-                reportFailure(tr("Not enough free ports on device for C++ debugging."));
-                return;
-            }
-        }
-        if (m_useQmlServer) {
-            m_qmlServerPort = m_portsGatherer.getNextFreePort(&portList);
-            if (!m_qmlServerPort.isValid()) {
-                reportFailure(tr("Not enough free ports on device for QML debugging."));
-                return;
-            }
-        }
-        reportStarted();
-    });
     m_portsGatherer.start(device());
 }
 
+void GdbServerPortsGatherer::handlePortListReady()
+{
+    Utils::PortList portList = device()->freePorts();
+    appendMessage(tr("Found %1 free ports").arg(portList.count()), NormalMessageFormat);
+    if (m_useGdbServer) {
+        m_gdbServerPort = m_portsGatherer.getNextFreePort(&portList);
+        if (!m_gdbServerPort.isValid()) {
+            reportFailure(tr("Not enough free ports on device for C++ debugging."));
+            return;
+        }
+    }
+    if (m_useQmlServer) {
+        m_qmlServerPort = m_portsGatherer.getNextFreePort(&portList);
+        if (!m_qmlServerPort.isValid()) {
+            reportFailure(tr("Not enough free ports on device for QML debugging."));
+            return;
+        }
+    }
+    reportStarted();
+}
 
 // GdbServerRunner
 
diff --git a/src/plugins/debugger/debuggerruncontrol.h b/src/plugins/debugger/debuggerruncontrol.h
index c22a4c969f5936ec35411983dbc0cb92ad1b5355..dc3b7a648a312f37ba9151b896c42557bdd5fb75 100644
--- a/src/plugins/debugger/debuggerruncontrol.h
+++ b/src/plugins/debugger/debuggerruncontrol.h
@@ -111,7 +111,8 @@ public:
     Utils::Port qmlServerPort() const { return m_qmlServerPort; }
 
 private:
-    void start();
+    void start() override;
+    void handlePortListReady();
 
     ProjectExplorer::DeviceUsedPortsGatherer m_portsGatherer;
     bool m_useGdbServer = false;