I'm trying to connect to wifi network using the following code but it is not working also not giving any error
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QNetworkConfiguration cfg;
QNetworkConfigurationManager ncm;
auto nc = ncm.allConfigurations();
for (auto &x : nc)
{
if (x.bearerType() == QNetworkConfiguration::BearerWLAN)
{
if (x.name() == "Desired Network")
qDebug() <<"Connecting to "<< x.name();
cfg = x;
}
}
auto session = new QNetworkSession(cfg);
session->open();
return a.exec();
}
It is showing the output in the terminal with "desired network's name".
Connecting to Desired Network
Actual NI names in your OS may be different from ones you expect. Try debug it more verbosely:
E.g. on Windows those names would be enclosed in quotes, most likely because of WMIC backend used by Qt to obtain them. If your NI is called "Desired Network" in GUI, it is actually
"\"Desired Network\""