diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp
index 5788164dc97f37bed9b598948a47f1b4fc355a77..5c09efa6339df454d7ea74400a8023ac85af349a 100644
--- a/src/plugins/debugger/debuggerrunner.cpp
+++ b/src/plugins/debugger/debuggerrunner.cpp
@@ -56,11 +56,10 @@
 
 #include <utils/qtcassert.h>
 #include <utils/qtcprocess.h>
-#include <utils/portlist.h>
-#include <utils/tcpportsgatherer.h>
 #include <coreplugin/icore.h>
 
 #include <QErrorMessage>
+#include <QTcpServer>
 
 using namespace Debugger::Internal;
 using namespace ProjectExplorer;
@@ -385,18 +384,14 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
                 DeviceKitInformation::device(runConfiguration->target()->kit());
         sp.qmlServerAddress = _("127.0.0.1");
         QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return sp);
-        TcpPortsGatherer portsGatherer;
-        portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol);
-        Utils::PortList portList = device->freePorts();
-        int freePort = portsGatherer.getNextFreePort(&portList);
-        if (freePort == -1) {
+        QTcpServer server;
+        const bool canListen = server.listen(QHostAddress(sp.qmlServerAddress));
+        if (!canListen) {
             if (errorMessage)
-                *errorMessage = DebuggerPlugin::tr("Not enough free ports for QML debugging. "
-                                                   "Increase the port range for Desktop device in "
-                                                   "Device settings.");
+                *errorMessage = DebuggerPlugin::tr("Not enough free ports for QML debugging. ");
             return sp;
         }
-        sp.qmlServerPort = freePort;
+        sp.qmlServerPort = server.serverPort();
         sp.languages |= QmlLanguage;
 
         // Makes sure that all bindings go through the JavaScript engine, so that
diff --git a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp
index 51480d0dd6ecb1fbc52b8b078e76218e7a1c76f2..18eca2326ea65b575d184476540296061b1b9dfe 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp
@@ -37,7 +37,6 @@
 #include <projectexplorer/project.h>
 #include <projectexplorer/projectexplorer.h>
 #include <utils/qtcprocess.h>
-#include <utils/tcpportsgatherer.h>
 
 #include <debugger/debuggerrunner.h>
 #include <debugger/debuggerplugin.h>
@@ -47,6 +46,8 @@
 
 #include <qmlprojectmanager/qmlprojectplugin.h>
 
+#include <QTcpServer>
+
 using namespace ProjectExplorer;
 
 namespace QmlProjectManager {
@@ -219,17 +220,14 @@ RunControl *QmlProjectRunControlFactory::createDebugRunControl(QmlProjectRunConf
                 DeviceKitInformation::device(runConfig->target()->kit());
         params.qmlServerAddress = QLatin1String("127.0.0.1");
         QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);
-        Utils::TcpPortsGatherer portsGatherer;
-        portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol);
-        Utils::PortList portList = device->freePorts();
-        int freePort = portsGatherer.getNextFreePort(&portList);
-        if (freePort == -1) {
+        QTcpServer server;
+        const bool canListen = server.listen(QHostAddress(params.qmlServerAddress));
+        if (!canListen) {
             if (errorMessage)
-                *errorMessage = tr("Not enough free ports for QML debugging. Increase the "
-                                   "port range for Desktop device in Device settings.");
+                *errorMessage = tr("Not enough free ports for QML debugging. ");
             return 0;
         }
-        params.qmlServerPort = freePort;
+        params.qmlServerPort = server.serverPort();
         params.languages |= Debugger::QmlLanguage;
 
         // Makes sure that all bindings go through the JavaScript engine, so that