Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Detecting WiFi network
Forum Updated to NodeBB v4.3 + New Features

Detecting WiFi network

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
25 Posts 8 Posters 8.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ashajgA ashajg

    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.
    CHECK1

    It 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 = WiFi

    please help!!!
    Thanks and Regards
    Ashish

    K Offline
    K Offline
    koahnig
    wrote on last edited by
    #2

    @ashajg

    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();
       }
    }
    

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    1
    • ashajgA Offline
      ashajgA Offline
      ashajg
      wrote on last edited by
      #3

      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 1

      Still not getting wifi names

      1 Reply Last reply
      0
      • ashajgA Offline
        ashajgA Offline
        ashajg
        wrote on last edited by
        #4

        Hi @koahnig

        CHECK1 1<- this is returned by x.bearerType

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Hi,

          @ashajg said in Detecting WiFi network:

          Hi @koahnig

          CHECK1 1<- this is returned by x.bearerType

          From the documentation: QNetworkConfiguration::BearerEthernet

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • ashajgA Offline
            ashajgA Offline
            ashajg
            wrote on last edited by
            #6

            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??

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #7

              Might be a silly question: is your WiFi device enabled ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • ashajgA Offline
                ashajgA Offline
                ashajg
                wrote on last edited by
                #8

                YES my device is enabled

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  Eeli K
                  wrote on last edited by
                  #9

                  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.

                  1 Reply Last reply
                  0
                  • ashajgA Offline
                    ashajgA Offline
                    ashajg
                    wrote on last edited by
                    #10

                    @SGaist

                    What all things can i try to solve this problem??
                    Is there a problem in code ??

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      A call to updateConfigurations is likely required.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • ashajgA Offline
                        ashajgA Offline
                        ashajg
                        wrote on last edited by
                        #12

                        ok i ll try that.

                        1 Reply Last reply
                        0
                        • ashajgA Offline
                          ashajgA Offline
                          ashajg
                          wrote on last edited by
                          #13

                          @SGaist
                          I tried but nothing happened

                          I have found this
                          https://forum.qt.io/topic/47384/qt-connecting-to-wireless-networks/4

                          what is qgenericbearer.dll and qnativewifibearer.dll and is it needed for this program??

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1
                            • ashajgA Offline
                              ashajgA Offline
                              ashajg
                              wrote on last edited by
                              #15

                              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??

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                What plugins do you have ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  Eeli K
                                  wrote on last edited by
                                  #17

                                  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.

                                  1 Reply Last reply
                                  1
                                  • ashajgA Offline
                                    ashajgA Offline
                                    ashajg
                                    wrote on last edited by
                                    #18

                                    I have qgenericbearer.dll only @SGaist

                                    1 Reply Last reply
                                    0
                                    • ashajgA Offline
                                      ashajgA Offline
                                      ashajg
                                      wrote on last edited by
                                      #19

                                      Hi @Eeli-K what else can I use other than QNetworkConfigurationManager if I want to use unpaid version of Qt...

                                      1 Reply Last reply
                                      0
                                      • E Offline
                                        E Offline
                                        Eeli K
                                        wrote on last edited by
                                        #20

                                        I think you have to use platform-native APIs instead of Qt.

                                        1 Reply Last reply
                                        0
                                        • dheerendraD Offline
                                          dheerendraD Offline
                                          dheerendra
                                          Qt Champions 2022
                                          wrote on last edited by
                                          #21

                                          Did you solve this issue using native APIs ?

                                          Dheerendra
                                          @Community Service
                                          Certified Qt Specialist
                                          http://www.pthinks.com

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved