Unsolved Detecting WiFi network
-
Re: Qt - Connecting to wireless networks
Hi guys
I am trying to write code which will detect WiFi.
My program:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QNetworkConfiguration>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);QGuiApplication app(argc, argv); QQmlApplicationEngine engine; ////////////////////////////////////// QNetworkConfiguration cfg; QNetworkConfigurationManager ncm; auto nc = ncm.allConfigurations(); for (auto &x : nc) {qDebug()<< "CHECK1"; if (x.bearerType() == QNetworkConfiguration::BearerWLAN) { qDebug ()<<"CHECK2"; qDebug() <<"WIFI is"<<x.name(); } } ///////////////////////////////////// engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec();
}
I am unable to get WiFi names..
Result:
Starting C:\Ashish\QTPROJECT\build-untitled-Desktop_Qt_5_11_0_MinGW_32bit-Debug\debug\WiFi.exe...
QML debugging is enabled. Only use this in a safe environment.
CHECK1It seems program control is not entering inside if (x.bearerType() == QNetworkConfiguration::BearerWLAN) loop.
In Pro file i have added :QT += quick network
CONFIG += c++11
TARGET = WiFiplease help!!!
Thanks and Regards
Ashish -
Try this to see what is available.
for (auto &x : nc) { qDebug()<< "CHECK1 " << x.bearerType(); if (x.bearerType() == QNetworkConfiguration::BearerWLAN) { qDebug ()<<"CHECK2"; qDebug() <<"WIFI is"<<x.name(); } }
-
Hi @koahnig
I tried above code
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QNetworkConfiguration>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
////////////////////////////////////////////////
QStringList WiFisList;
QNetworkConfiguration cfg;
QNetworkConfigurationManager ncm;
auto nc = ncm.allConfigurations();for (auto &x : nc) { qDebug()<< "CHECK1 " << x.bearerType(); if (x.bearerType() == QNetworkConfiguration::BearerWLAN) { qDebug ()<<"CHECK2"; qDebug() <<"WIFI is"<<x.name(); } } ///////////////////////////////////// engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec();
}
Result:
Starting C:\Ashish\QTPROJECT\build-wifi-Desktop_Qt_5_11_0_MinGW_32bit-Debug\debug\WiFi.exe...
QML debugging is enabled. Only use this in a safe environment.
CHECK1 1Still not getting wifi names
-
Hi @koahnig
CHECK1 1<- this is returned by x.bearerType
-
Hi,
@ashajg said in Detecting WiFi network:
Hi @koahnig
CHECK1 1<- this is returned by x.bearerType
From the documentation:
QNetworkConfiguration::BearerEthernet
-
hi @SGaist
yes its Ethernet....
Dont know why it is getting set to ethernet and not working for wifi......
for this code are some plugins required??
-
Might be a silly question: is your WiFi device enabled ?
-
YES my device is enabled
-
I'm loosing my nerves with this, too. I didn't notice this topic but wrote in the General section: https://forum.qt.io/topic/96157/how-to-get-the-current-ssid-what-are-qnetworkconfigurations. I just don't understand what these classes are even supposed to do.
-
What all things can i try to solve this problem??
Is there a problem in code ?? -
A call to updateConfigurations is likely required.
-
ok i ll try that.
-
@SGaist
I tried but nothing happenedI have found this
https://forum.qt.io/topic/47384/qt-connecting-to-wireless-networks/4what is qgenericbearer.dll and qnativewifibearer.dll and is it needed for this program??
-
The bearer plugins are responsible for providing the backend to the system networking capabilities so yes they are needed but the names are not the same for all the platforms.
-
Ok @SGaist
In my Qt , I checked and found that in plugin/bearer I don't have qnativewifibearer.....
Do I just need to download it and paste it in my Qt plugin folder??
-
What plugins do you have ?
-
It looks like QNetworkConfigurationManager can't be trusted nowadays, see for example https://bugreports.qt.io/browse/QTBUG-68613 and https://bugreports.qt.io/browse/QTBUG-65586.
-
I have qgenericbearer.dll only @SGaist
-
Hi @Eeli-K what else can I use other than QNetworkConfigurationManager if I want to use unpaid version of Qt...
-
I think you have to use platform-native APIs instead of Qt.