summaryrefslogtreecommitdiff
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2023-01-26 13:16:43 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2023-02-09 18:55:37 +0100
commit0f50145e433d2ac4ad2f4371ce627d2e0c2e0efd (patch)
treed6b5718bdb5dda54cb02b426f9585109fb071115 /src/corelib/global
parent08ea2c5dc8203c89c61a38047d2e8c68fb403e06 (diff)
downloadqtbase-0f50145e433d2ac4ad2f4371ce627d2e0c2e0efd.tar.gz
QSysInfo: Work around erroneous warning output from Windows
gethostname is in no way labeled deprecated, but it _tries_ to query some deprecated functionality, thus some warning like this is printed: "" LogHr(1) tid(6e14) 8007277C No such service is known. The service cannot be found in the specified name space. "" By using GetComputerNameEx we work around that. Bonus side effect is that it gives us UTF-16 right away so we save a conversion. Fixes: QTBUG-110468 Pick-to: 6.5 Change-Id: I3a370354d9cce50e3d89d125ce61fc9b619294cc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qsysinfo.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/corelib/global/qsysinfo.cpp b/src/corelib/global/qsysinfo.cpp
index 0502e77177..dace55b6ce 100644
--- a/src/corelib/global/qsysinfo.cpp
+++ b/src/corelib/global/qsysinfo.cpp
@@ -938,13 +938,26 @@ QString QSysInfo::machineHostName()
# ifdef Q_OS_WIN
// Important: QtNetwork depends on machineHostName() initializing ws2_32.dll
winsockInit();
-# endif
+ QString hostName;
+ hostName.resize(512);
+ unsigned long len = hostName.size();
+ BOOL res = GetComputerNameEx(ComputerNameDnsHostname,
+ reinterpret_cast<wchar_t *>(const_cast<quint16 *>(hostName.utf16())), &len);
+ if (!res && len > 512) {
+ hostName.resize(len - 1);
+ GetComputerNameEx(ComputerNameDnsHostname,
+ reinterpret_cast<wchar_t *>(const_cast<quint16 *>(hostName.utf16())), &len);
+ }
+ hostName.truncate(len);
+ return hostName;
+# else // !Q_OS_WIN
char hostName[512];
if (gethostname(hostName, sizeof(hostName)) == -1)
return QString();
hostName[sizeof(hostName) - 1] = '\0';
return QString::fromLocal8Bit(hostName);
+# endif
#endif
}
#endif // QT_BOOTSTRAPPED