How to get hostname using Qt?

How to get the hostname of my desktop pc?

To get system information for Symbian OS:

http://developer.nokia.com/community/wiki/Get_device_information_using_Qt

+5
source share
2 answers

You are probably looking for the following:

[static] QString QHostInfo :: localHostName ()

Returns the host name of this device.

main.cpp

#include <QHostInfo> #include <QDebug> int main() { qDebug() << QHostInfo::localHostName(); return 0; } 

main.pro

 TEMPLATE = app TARGET = main QT = core network SOURCES += main.cpp 

Assembly and launch

 qmake && make && ./main 

Exit

 "myhostname" 
+10
source

Do you know what QHostInfo class is?

http://doc.qt.io/qt-4.8/qhostinfo.html

 qDebug(QHostInfo::localHostName().toLocal8Bit()); 
0
source

Source: https://habr.com/ru/post/1209434/


All Articles