Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the hostname using Qt?

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

like image 237
Chawki Messaoudi Avatar asked Dec 18 '14 09:12

Chawki Messaoudi


2 Answers

you know that class QHostInfo?

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

qDebug(QHostInfo::localHostName().toLocal8Bit());
like image 133
Marvvvv Avatar answered Nov 10 '22 16:11

Marvvvv


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"
like image 19
lpapp Avatar answered Nov 10 '22 17:11

lpapp