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. QNetworkAccessManager::setNetworkAccessible useful but DEPRECATED
QtWS25 Last Chance

QNetworkAccessManager::setNetworkAccessible useful but DEPRECATED

Scheduled Pinned Locked Moved Unsolved General and Desktop
networkaccessmanagernetworkaccessaccessqt5
5 Posts 2 Posters 1.4k 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.
  • S Offline
    S Offline
    sangioQtDev
    wrote on last edited by sangioQtDev
    #1

    Hi,
    i'm an absolute begginer of Qt framework.
    I need help figuring out other ways to connect to devices placed in my INTRANET having no internet access state.

    My task is to send http request to a device located in my intranet. It responds to ping checks: so is REACHABLE.

    I've been using QNetworkAccessManager among other things , and apparently it reflects the actual device state.
    So even if the device is physically reachable, whenever I don't have internet access (so not able to ping 8.8.8.8) and my physical device internet state is saying "No internet access", QNetworkAccessManager treats all outgoing calls as wrong and doesn't send them, then it raises erros like "access to internet disabled" .

    I solved it forcing the Network accessibility flag by using:
    "QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::Accessible)" .
    After that everything works fine even without internet connetion.

    Anyway since this method is explicity marked DEPRECATED in Qt5 and ELIMINATED in Qt6, i'm calling out for help in order to find other ways to overcome this problem!!

    Here is some code:

                //instanciate QNetworkAccessManager
                QNetworkAccessManager *manager = new QNetworkAccessManager(this);
                
                //forcing state of network accessibility state
                manager->setNetworkAccessible(QNetworkAccessManager::Accessible); // --> try without it
                
                //creating QNetworkRequest
                QNetworkRequest request;
                QString url = QString("http://192.168.0.111/www/index.html"); //a random server page in my intranet
                request.setUrl(QUrl(url));
    
                //sending request
                QNetworkReply *reply = manager->get(request);
    
                qDebug() << "Sending GET";
                
                //getting ready to read responses
                connect(reply, &QIODevice::readyRead,
                        [](){
                            qDebug() << "READYREAD";
                });
                connect(reply, &QNetworkReply::errorOccurred,
                        [](QNetworkReply::NetworkError err){
                            qDebug() << "ERROR :" << err;
                });
                connect(reply, &QNetworkReply::sslErrors,
                        [](const QList<QSslError> &errors){
                                qDebug() << "SSLErrors";
                });
    
    
    

    Thank you all in advance!!

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

      Hi and welcome to devnet,

      How are you reaching that device of yours ? IP address ? Hostname ?

      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
      • S Offline
        S Offline
        sangioQtDev
        wrote on last edited by
        #3

        Hi @SGaist,
        everything via IP address.

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

          Did you already tried with Qt 6 ?
          The complete bearer stack has been removed so you might not have that issue there.

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

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            Did you already tried with Qt 6 ?
            The complete bearer stack has been removed so you might not have that issue there.

            S Offline
            S Offline
            sangioQtDev
            wrote on last edited by
            #5

            @SGaist I didn't in fact ( and I can't in the short term).

            Just to clarify I'll mention the documentation related to this 'bearer stack removal' : Qt Network in Qt 6.
            It also leads to QTBUG-86966 where QNetworkInformation is presented as solution for "Reachability" device state checks!!

            However I still can't find anything that tells me how to overcome my "NoInternetAccess" device state related problem.

            But that's great news!!
            Maybe my problem has already been taken care of.

            Thanks!!

            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