From 49e1aa98bf8129960c3e09d6a95781c304df274f Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm Date: Tue, 9 Jun 2026 08:46:51 +0200 Subject: [PATCH] Resolve host address via dns --- src/mainobject.cpp | 3 ++- src/service/tcpclient.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mainobject.cpp b/src/mainobject.cpp index 95623fb..b84a48f 100644 --- a/src/mainobject.cpp +++ b/src/mainobject.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "mqttclient.h" #include "items/mqttitem.h" @@ -169,7 +170,7 @@ SecondaryMainObject::SecondaryMainObject(QString host, int port, QObject *parent globalItems.registerItemSource(tcpClient); connect(&globalSensors, &SensorStore::sensorChangedState, tcpClient, &TcpClient::sensorEvent); - if(!tcpClient->launch(QHostAddress(host), port)) + if(!tcpClient->launch(QHostInfo::fromName(host).addresses()[0], port)) { QMessageBox::critical(nullptr, "Error", "Could not connect to "+host+":"+QString::number(port)); QMetaObject::invokeMethod(this, [](){exit(1);}, Qt::QueuedConnection); diff --git a/src/service/tcpclient.cpp b/src/service/tcpclient.cpp index ef2fc66..5c43446 100644 --- a/src/service/tcpclient.cpp +++ b/src/service/tcpclient.cpp @@ -23,7 +23,12 @@ void TcpClient::sendJson(const QJsonObject& json) bool TcpClient::launch(const QHostAddress &address, quint16 port) { socket->connectToHost(address, port); - return socket->waitForConnected(2000); + if(!socket->waitForConnected(4000)) + { + qWarning()<<"Unable to connect to "<error(); + return false; + } + return true; } void TcpClient::processIncomeingJson(const QByteArray& jsonbytes)