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. Connect to a Wifi network - without c++11 (without 'auto')
QtWS25 Last Chance

Connect to a Wifi network - without c++11 (without 'auto')

Scheduled Pinned Locked Moved General and Desktop
qt4c++11
12 Posts 5 Posters 4.9k Views
  • 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.
  • Z Offline
    Z Offline
    zarachbaal
    wrote on 15 Jun 2015, 15:48 last edited by
    #1

    Hi all,

    I am currectly developping two applications, one of them runs on an android device, it activates the Wifi hotspot and waits for someone to connect to it.
    When someone is connected, it has to send a message (string) each time a button is clicked.

    The second application is a pretty big project that has been started a while ago (with Qt 4.8.4), I have to add the possibility to connect to the phone's hotspot and wait for a message to be received.
    I have found an easy way to connect to a Wifi network :

    QNetworkConfiguration cfg;
    QNetworkConfigurationManager ncm;
    auto nc = ncm.allConfigurations();
    
    for (auto &x : nc)
    {
    	if (x.bearerType() == QNetworkConfiguration::BearerWLAN)
    	{
    		if (x.name() == "YouDesiredNetwork")
    			cfg = x;
    	}
    }
    
    auto session = new QNetworkSession(cfg, this);
    session->open();
    

    Unfortunately this code uses c++11 syntax, and I can't get it working on my Qt 4.8.4.
    Adding "QMAKE_CXXFLAGX += -std=c++0x" causes "::swprintf and ::vswprintf has not been declared".
    Wrapping their declaration in 'cwchar' with

    #ifndef __STRICT_ANSI__
        using ::swprintf;
        using ::vswprintf;
    #endif
    

    Causes crash because of segmentation fault.

    I was wondering if it was possible to connect to a Wifi Network without c++11 syntax ?
    I guess it is, but I am not familiar with c++11 so I'm ,not sure how to modify the code.

    Any help would be appreciated

    Thank you in advance

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Jun 2015, 16:19 last edited by
      #2

      Hi,

      I don't remember if CONFIG += c++11 was already working for that version of Qt.

      In any case you should just replace auto with the correct classes name and use foreach from Qt

      QList<QNetworkConfiguration> ncs = ncm.allConfigurations();
      foreach(const QNetworkConfiguration &configuration, ncList) {
      // rest is the same as before
      

      Hope it helps

      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
      • Z Offline
        Z Offline
        zarachbaal
        wrote on 16 Jun 2015, 12:01 last edited by zarachbaal
        #3

        Hi,

        thanks for your help, it compiles without error now.

        Unfortunately, it crashes at runtime (I do have added 'CONFIG += network' in my .pro file).
        Weirdly, it doesn't crash on debug.

        If I comment this part :

        ncs = ncm.allConfigurations();
        foreach (const QNetworkConfiguration &configuration, ncs) {
            if(configuration.bearerType() == QNetworkConfiguration::BearerWLAN)
            {
                if(configuration.name() == "JBLiagre.com")
                {
                    m_notif_ui->label_connexion->setStyleSheet("QLabel{color : green;}");
                    m_notif_ui->label_connexion->setText("Connecté à 'JBLiagre.com'  !");
                    m_notif_ui->label_connexion->setAlignment(Qt::AlignCenter);
                    cfg = configuration;
                }
            }
        }
        

        It runs without any problem.
        I am waiting for the IT departement to give me a Wifi-card so for the moment I do not have Wifi on my computer, could this be related ?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on 16 Jun 2015, 13:07 last edited by
          #4

          @zarachbaal said:

          cfg = configuration;

          how and where is cfg defined and used??
          Have you able to collect the crash dump??

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zarachbaal
            wrote on 16 Jun 2015, 13:45 last edited by zarachbaal
            #5

            My full code related to QtNetwork is :

            #include <QtNetwork/QtNetwork>
            
            QNetworkConfiguration cfg;
            QNetworkConfigurationManager ncm;
            QList<QNetworkConfiguration> ncs;
            
            ncs = ncm.allConfigurations();
            foreach (const QNetworkConfiguration &configuration, ncs) {
                if(configuration.bearerType() == QNetworkConfiguration::BearerWLAN)
                {
                    if(configuration.name() == "test.com")
                    {
                        cfg = configuration;
                    }
                }
            }
            

            If I comment everything but :

            #include <QtNetwork/QtNetwork>
            
            QNetworkConfiguration cfg;
            QNetworkConfigurationManager ncm;
            QList<QNetworkConfiguration> ncs;
            
            ncs = ncm.allConfigurations();
            

            It crashes too.

            What do you mean by "collecting the crash dump" ?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 16 Jun 2015, 20:56 last edited by
              #6

              When you have a crash you generally get a stack trace (if you are using a debug build) so you can see where exactly the problem happened

              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
              • Z Offline
                Z Offline
                zarachbaal
                wrote on 17 Jun 2015, 13:24 last edited by
                #7

                Ok that's what I thought.

                The problem is that in Debug mode (via F5 in Qt Creator), my program doesn't crash so I won't be able to post the crash dump.

                I will try my program this evening on a computer that has a Wifi card to see if it changes anything.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 17 Jun 2015, 13:43 last edited by
                  #8

                  Is the crash happening in Qt Creator with a release build ?

                  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
                  • Z Offline
                    Z Offline
                    zarachbaal
                    wrote on 17 Jun 2015, 15:21 last edited by
                    #9

                    Yes it is

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alex_malyu
                      wrote on 17 Jun 2015, 22:14 last edited by
                      #10

                      Qt4.8 :

                      Tier 1 Platforms

                      All Tier 1 platforms are subjected to our unit test suite and other internal testing tools on a frequent basis (prior to new version releases, source tree branching, and at other significant period points in the development process). Errors or bugs discovered in these platforms are prioritized for correction by the development team. Significant errors discovered in Tier 1 platforms can impact release dates and Qt Development Frameworks strives to resolve all known high priority errors in Tier 1 platforms prior to new version releases.

                      Platform Compilers
                      Ubuntu Linux 10.04 (32-bit) As provided by Ubuntu
                      Ubuntu Linux 11.10 (64-bit) As provided by Ubuntu
                      Microsoft Windows XP SP3 (32-bit) MSVC 2008
                      Microsoft Windows 7 (32-bit) MSVC 2008
                      Microsoft Windows 7 (32-bit) MSVC 2010 SP1
                      Apple Mac OS X 10.6 "Snow Leopard" (64-bit) As provided by Apple
                      Apple Mac OS X 10.7 "Lion" (64-bit) As provided by Apple
                      Tier 2 Platforms

                      Tier 2 platforms are subject to ad hoc and internal testing. However, Qt users should note that errors may be present in released product versions for Tier 2 platforms and, subject to resource availability, known errors in Tier 2 platforms may or may not be corrected prior to new version releases.

                      Platform Compilers
                      Ubuntu Linux 10.04 QWS (x86 32-bit) As provided by Ubuntu
                      Ubuntu Linux 10.04 (32-bit) Intel Compiler [version 12]
                      Ubuntu Linux 10.04 (64-bit) As provided by Ubuntu
                      Microsoft Windows XP SP3 (32-bit) GCC 4.4 (MinGW)
                      Microsoft Windows XP SP3 (32-bit) MinGW-builds gcc 4.8.2 (32 bit)
                      Microsoft Windows 7 (64-bit) MSVC 2010 SP1
                      Apple Mac OS X 10.6 "Snow Leopard" Cocoa (32-bit) As provided by Apple

                      I am not sure about other, but none of the Microsoft compilers listed provided full C++11
                      support.

                      I know only one way to debug release code print out information on the screen.

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        zarachbaal
                        wrote on 18 Jun 2015, 11:49 last edited by
                        #11

                        I just created a new project and added the code above.
                        It works well, no errors or crashes.
                        So the problem is in my project, I will look into it but I do not see what could cause the problem.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gyll
                          wrote on 18 Jun 2015, 12:38 last edited by
                          #12

                          maybe you should also try finding the problem (in the release version) the old fashion way: just place cout<<"line X" statements here and there and pinpoint the line where the problem occurs

                          1 Reply Last reply
                          0

                          8/12

                          17 Jun 2015, 13:43

                          • Login

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