There must be a way to read the list of available WiFi SSIDs using Qt?
Attempted:
QNetworkConfigurationManager nwkMgr;
// UPDATE:
// Need to call nwkMgr.updateConfigurations() here
// UPDATE this code needs to run in the slot for QNetworkManager::updateCompleted signal
QList<QNetworkConfiguration> nwkCnfList = nwkMgr.allConfigurations();
for(const QNetworkConfiguration &ncnf : nwkCnfList)
{
qDebug() << ncnf.name() << ncnf.bearerType();
if (ncnf.bearerType() == QNetworkConfiguration::BearerWLAN)
{
// would like to detect WiFi here
qDebug() << "WiFi:" << ncnf.name();
}
}
The environment is Qt 5.7 and OS X El Capitan 10.11.6. The output is:
"en1" 0
"en5" 0
"en2" 0
"bridge0" 0
"p2p0" 0
"awdl0" 0
"gif0" 0
"stf0" 0
"en0" 0
"fw0" 0
UPDATE: The result above with interfaces instead of SSIDs is for the first run of the code sample. I've added the Refresh button for my cross-platform app and attempted to do the 'refresh' on Mac as well and the second run several seconds after app start up shows interfaces followed by SSIDs of all the networks available. That must be some Qt bug (?) which I intend to report.
But the same code above on both Windows and Linux Ubuntu outputs real SSIDs and finds WiFi. The desired (but I want all not only 'preferred') list of WiFi networks can be obtained from command line:
bash-3.2$ networksetup -listpreferredwirelessnetworks en0
Preferred networks on en0:
WiFi-N1
WiFi-N2
WiFi-N3
....
WiFi-NN
I also read on calling airport program from command line to get all WiFi networks and there is a long path to the framework binary directory which I don't want to hardcode.
Please suggest how to deal with it. The worst case ia to deal with MacOS API (in C++) here and it is also acceptable. The goal is to having read SSIDs let the user to open one WiFi connection with Qt and the initiate some 'exchange' via it. If the password needs to be provided we can even deal with 'preferred' pre-set connection but that'd be better to handle it programmatically as well.