Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QNetworkAccessManager::setNetworkAccessible useful but DEPRECATED



  • 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!!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

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



  • Hi @SGaist,
    everything via IP address.


  • Lifetime Qt Champion

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



  • @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!!