On Ubuntu 15, if the network is disabled using the notification tray icon, then network requests fail (as expected). The first failure is 'NetworkSessionFailedError' and subsequent failures are 'UnknownNetworkError'. But even once the network is reenabled, the network requests continue to fail indefinitely (still with 'UnknownNetworkError').
Demo code and log from sample run shown below.

I also tested on Windows and the problem did not happen (i.e. requests resume normally after network is reconnected).

How do I make Ubuntu behave the same as Windows? Do I need to 'reset' the Qt network stack or something when I have an error on this platform?

I am a novice so it's probably just something simple I forgot. Any suggestions much appreciated!

=== CODE ===

#include <memory>
#include <QtCore>
#include <QtNetwork>

int main(int argc, char *argv[]) {
    QCoreApplication application(argc, argv);

    QNetworkAccessManager networkAccessManager;

    while (true) {
        QEventLoop loop;

        QNetworkRequest request;
        request.setUrl(QUrl("http://www.google.com/";));

        qDebug() << QTime::currentTime() << "GET/POST";
std::unique_ptr<QNetworkReply> reply(networkAccessManager.get(request)); QObject::connect(&*reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
            [&loop](QNetworkReply::NetworkError error) {
                qDebug() << QTime::currentTime() << "error" << error;
                loop.quit();
            }
        );
        QObject::connect(&*reply, &QNetworkReply::finished,
            [&loop]() {
                qDebug() << QTime::currentTime() << "finished";
                loop.quit();
            }
        );

        loop.exec();

        QThread::sleep(1);
    }

    return application.exec();
}

=== LOG ===

QTime("19:16:00.441") GET/POST
qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method
qt.network.ssl: QSslSocket: cannot resolve SSLv2_server_method
QTime("19:16:01.015") finished
QTime("19:16:02.016") GET/POST
QTime("19:16:02.551") finished
QTime("19:16:03.551") GET/POST
QTime("19:16:04.177") finished
QTime("19:16:05.177") GET/POST
QTime("19:16:05.595") finished
QTime("19:16:06.596") GET/POST
QTime("19:16:07.130") finished
QTime("19:16:08.130") GET/POST
QTime("19:16:13.038") error QNetworkReply::NetworkError(NetworkSessionFailedError)
QTime("19:16:13.046") finished
QTime("19:16:14.048") GET/POST
QTime("19:16:14.049") error QNetworkReply::NetworkError(UnknownNetworkError)
QTime("19:16:14.049") finished
QTime("19:16:15.050") GET/POST
QTime("19:16:15.050") error QNetworkReply::NetworkError(UnknownNetworkError)
QTime("19:16:15.050") finished
QTime("19:16:16.053") GET/POST
QTime("19:16:16.053") error QNetworkReply::NetworkError(UnknownNetworkError)
QTime("19:16:16.053") finished

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to