sashoalm sashoalm - 10 months ago 149
C++ Question

Get local IP address in Qt

Is there a cross-platform way to get the local IP address (i.e. something that looks like

192.168.1.49
) of the computer using Qt?

I want to make an FTP server for a Symbian phone and I want to show the IP address the FTP client should connect to.

Answer Source

Use QNetworkInterface::allAddresses()

foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
    if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
         qDebug() << address.toString();
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download