There is a Qt program that exchanges files over a local network. It is necessary to add receipt of the list of hosts

foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) { if (address.protocol() == QAbstractSocket::IPv4Protocol && address !=QHostAddress(QHostAddress::LocalHost)) currenthost=address.toString(); } 

Getting a local address is done as follows. Then I just try to connect to each of the 255 sockets that may be on the local network by replacing the last digits of the local address with the numbers 1-255 and if the connection works, I write the address in the list

But if you run the program from a mobile device with mobile Internet, there will be no local network. How to catch such an event without using native checks on each platform?

  • for android you need to have permission to access the interface, added to AndroidManifest.xml, for iOS in my way - Pavel Gridin

1 answer 1

Qt has the ability to determine what happened to connect to the network http://doc.qt.io/qt-5/qnetworkconfiguration.html

If connected to a mobile network, there is definitely no lokalki.