Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Check Wireless State Change in qt

    General and Desktop
    4
    14
    2426
    Loading More Posts
    • 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.
    • F
      fireghostea last edited by fireghostea

      I want to connect some signal to my handler slot for notify me when wireless connection disconnect or when connect ( be carful I do not care for internet Access only check for connection to modem)
      I use "onlineStateChanged" in "QNetworkConfigurationManager" but it does not work Properly
      how I should do this?

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @fireghostea last edited by

        @fireghostea said in Check Wireless State Change in qt:

        I use "onlineStateChanged" in "QNetworkConfigurationManager" but it does not work Properly

        elaborate

        --- 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 Reply Quote 2
        • F
          fireghostea @raven-worx last edited by 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-worx 1 Reply Last reply Reply Quote 0
          • aha_1980
            aha_1980 Lifetime Qt Champion last edited by

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

            Qt has to stay free or it will die.

            F 1 Reply Last reply Reply Quote 1
            • mrjj
              mrjj Lifetime Qt Champion last edited by

              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 Reply Quote 2
              • raven-worx
                raven-worx Moderators @fireghostea last edited by

                @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 Reply Quote 1
                • F
                  fireghostea @aha_1980 last edited by

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

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @fireghostea last edited by

                    @fireghostea
                    So you do have 2 of them :)

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

                    1 Reply Last reply Reply Quote 1
                    • F
                      fireghostea @mrjj last edited by

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

                      mrjj 1 Reply Last reply Reply Quote 0
                      • mrjj
                        mrjj Lifetime Qt Champion @fireghostea last edited by 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 1 Reply Last reply Reply Quote 0
                        • F
                          fireghostea @raven-worx last edited by

                          @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 Reply Quote 0
                          • F
                            fireghostea @mrjj last edited by

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

                            mrjj 1 Reply Last reply Reply Quote 0
                            • mrjj
                              mrjj Lifetime Qt Champion @fireghostea last edited by 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-worx 1 Reply Last reply Reply Quote 2
                              • raven-worx
                                raven-worx Moderators @mrjj last edited by

                                @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 Reply Quote 1
                                • First post
                                  Last post