Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check Wireless State Change in qt
Qt 6.11 is out! See what's new in the release blog

Check Wireless State Change in qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 3.8k Views 2 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #5

    Hi
    One note. Can it be you have a ncm in the class ?
    As you say
    QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager();
    but use
    QObject::connect(&ncm, << the &

    if ncm is a pointer, using & wont compile.

    F 1 Reply Last reply
    2
    • F fireghostea

      @raven-worx said in Check Wireless State Change in qt:

      elaborate

      this is my simple code

      QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager();
      ChangeEvent *myhandler = new ChangeEvent ();
      QObject::connect(ncm, SIGNAL(onlineStateChanged(bool)), myhandler, SLOT(myslot(bool)));
      

      my slot in ChangeEvent class is

      void myslot(bool isonline);
      

      i expect from this code when i disconnect my wireless "myslot" function be call but does not work
      i ask this question in this link too link

      and some one provide me some code that works for his but does not work for me
      i use windows 10

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #6

      @fireghostea
      the online state is true when at least one connection/configuration is Active! Are you sure your WLAN connection is the only connection? (Beside Bluetooth, LAN, etc.)

      You should rather listen to the QNetworkManager's configuration related signals and check explicitly for WLAN configurations (bearer type is BearerWLAN)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      F 1 Reply Last reply
      1
      • aha_1980A aha_1980

        @fireghostea said in Check Wireless State Change in qt:

        ChangeEvent *myhandler = new ChangeEvent ();

        Is myhandler a local variable, i.e. when does myhandler get's destroyed?

        F Offline
        F Offline
        fireghostea
        wrote on last edited by
        #7

        @aha_1980 myhandler and ncm both define outside main function in main.cpp file

        mrjjM 1 Reply Last reply
        0
        • F fireghostea

          @aha_1980 myhandler and ncm both define outside main function in main.cpp file

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @fireghostea
          So you do have 2 of them :)

          QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager(); // no 2 then

          1 Reply Last reply
          1
          • mrjjM mrjj

            Hi
            One note. Can it be you have a ncm in the class ?
            As you say
            QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager();
            but use
            QObject::connect(&ncm, << the &

            if ncm is a pointer, using & wont compile.

            F Offline
            F Offline
            fireghostea
            wrote on last edited by
            #9

            @mrjj it is my mistake in writing post
            i edit my question

            mrjjM 1 Reply Last reply
            0
            • F fireghostea

              @mrjj it is my mistake in writing post
              i edit my question

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #10

              @fireghostea
              Ok, it was just to be sure.

              Update: was bored so tested.
              This works for me on win 10

              MainWindow::MainWindow(QWidget* parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow) {
                ui->setupUi(this);
              
                QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager(this);
                ncm->updateConfigurations(); // NOTE. was needed
                connect(ncm, &QNetworkConfigurationManager::onlineStateChanged, this,MainWindow::configurationStateChanged);
              }
              
              void MainWindow::configurationStateChanged(bool )
              {
                  qDebug()<< "online State Changed";
              }
              

              Disabling the net, i get this
              alt text

              Update: Just saw raven-worx. Sounds much better as i have only 1 interface and hence it works.

              F 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @fireghostea
                the online state is true when at least one connection/configuration is Active! Are you sure your WLAN connection is the only connection? (Beside Bluetooth, LAN, etc.)

                You should rather listen to the QNetworkManager's configuration related signals and check explicitly for WLAN configurations (bearer type is BearerWLAN)

                F Offline
                F Offline
                fireghostea
                wrote on last edited by
                #11

                @raven-worx with probability of 99% my problem is that you say
                because when i disconnect All connections and connect again my handler function call properly
                can you tell me how only focus on wireless ?

                1 Reply Last reply
                0
                • mrjjM mrjj

                  @fireghostea
                  Ok, it was just to be sure.

                  Update: was bored so tested.
                  This works for me on win 10

                  MainWindow::MainWindow(QWidget* parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow) {
                    ui->setupUi(this);
                  
                    QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager(this);
                    ncm->updateConfigurations(); // NOTE. was needed
                    connect(ncm, &QNetworkConfigurationManager::onlineStateChanged, this,MainWindow::configurationStateChanged);
                  }
                  
                  void MainWindow::configurationStateChanged(bool )
                  {
                      qDebug()<< "online State Changed";
                  }
                  

                  Disabling the net, i get this
                  alt text

                  Update: Just saw raven-worx. Sounds much better as i have only 1 interface and hence it works.

                  F Offline
                  F Offline
                  fireghostea
                  wrote on last edited by
                  #12

                  @mrjj i test this code and not work for me
                  and i guess this is because i have multi interface
                  how i should focus on only wifi interface ?

                  mrjjM 1 Reply Last reply
                  0
                  • F fireghostea

                    @mrjj i test this code and not work for me
                    and i guess this is because i have multi interface
                    how i should focus on only wifi interface ?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #13

                    @fireghostea

                    I think he thinks of these signals
                    void configurationAdded(const QNetworkConfiguration &config);
                    void configurationRemoved(const QNetworkConfiguration &config);
                    void configurationChanged(const QNetworkConfiguration &config);

                    There you get an QNetworkConfiguration and it has a
                    BearerType bearerType() const;

                    so if that returns BearerWLAN, its the one you want.

                    I have no wifi to test with but i assume that configurationChanged will trigger and if its right type
                    then you should have the state.

                    Hopefully that was what mr @raven-worx ment :)

                    raven-worxR 1 Reply Last reply
                    2
                    • mrjjM mrjj

                      @fireghostea

                      I think he thinks of these signals
                      void configurationAdded(const QNetworkConfiguration &config);
                      void configurationRemoved(const QNetworkConfiguration &config);
                      void configurationChanged(const QNetworkConfiguration &config);

                      There you get an QNetworkConfiguration and it has a
                      BearerType bearerType() const;

                      so if that returns BearerWLAN, its the one you want.

                      I have no wifi to test with but i assume that configurationChanged will trigger and if its right type
                      then you should have the state.

                      Hopefully that was what mr @raven-worx ment :)

                      raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #14

                      @fireghostea said in Check Wireless State Change in qt:

                      can you tell me how only focus on wireless ?

                      @mrjj said in Check Wireless State Change in qt:

                      Hopefully that was what mr @raven-worx ment :)

                      exactly.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      1

                      • Login

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