sashoalm sashoalm - 2 years ago 282
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
) 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