examples/network/fortuneserver/server.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    66     QString ipAddress;
    66     QString ipAddress;
    67     QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    67     QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    68     // use the first non-localhost IPv4 address
    68     // use the first non-localhost IPv4 address
    69     for (int i = 0; i < ipAddressesList.size(); ++i) {
    69     for (int i = 0; i < ipAddressesList.size(); ++i) {
    70         if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
    70         if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
    71             ipAddressesList.at(i).toIPv4Address())
    71             ipAddressesList.at(i).toIPv4Address()) {
    72             ipAddress = ipAddressesList.at(i).toString();
    72             ipAddress = ipAddressesList.at(i).toString();
       
    73             break;
       
    74         }
    73     }
    75     }
    74     // if we did not find one, use IPv4 localhost
    76     // if we did not find one, use IPv4 localhost
    75     if (ipAddress.isEmpty())
    77     if (ipAddress.isEmpty())
    76         ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
    78         ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
    77     statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n"
    79     statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n"