D
D
DDD2021-12-29 19:19:06
Qt
DDD, 2021-12-29 19:19:06

How to get Gateway in qt?

I use the QNetworkInterface and QHostInfo library but I can't get to the gateway, what could be the problem?

QString Gateway = QHostInfo::localHostName();
      QList<QHostAddress> hostGateway = QHostInfo::fromName(Gateway).addresses();
       foreach (const QHostAddress& address, hostGateway) {
           if (address.protocol() == QAbstractSocket::IPv4Protocol && address.isLoopback() == false) {
                Gateway = address.toString();
           }
       }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question