How to get the hostname using Qt?
Asked Answered
S

2

12

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

Sexennial answered 18/12, 2014 at 9:43 Comment(2)
you can simply call system("hostname"); or #505310Williamson
@Velthune: it is a Qt question (from yesterday).Mariner
K
19

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"
Kranz answered 18/12, 2014 at 11:53 Comment(0)
B
2

you know that class QHostInfo?

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

qDebug(QHostInfo::localHostName().toLocal8Bit());
Biogenesis answered 18/12, 2014 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.