How to get the hostname using Qt?

Chawki Messaoudi picture Chawki Messaoudi · Dec 18, 2014 · Viewed 12.6k times · Source

How to get the host name of my desktop PC?

Like this, to get system information for Symbian OS:

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

Answer

lpapp picture lpapp · Dec 18, 2014

You are probably look for this:

[static] QString QHostInfo::​localHostName()

Returns the host name of this machine.

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

Build and Run

qmake && make && ./main

Output

"myhostname"