user3434662
user3434662

Reputation: 409

QNetworkAccessManager Error Code 99; Only on Some Systems…

When using QNetworkAccessManager I get a strange error that only occurs on some systems but not others.

See below for the code. The test below connects to an SSL-based site.

I have OpenSSL DLLs (libeay32.dll and ssleay32.dll) on the client systems in the same directory as my application but the error still occurs.

The error code is (99) – Unknown Network Error.

What causes this error on some systems but not others?

What can I do to fix?

Thank you for your time.

In the constructor of the application: MainNetConnector = new QNetworkAccessManager(this);

The function that starts the test:

void QTBasicWidget::performNetworkTest() {

    QMessageBox::StandardButton RequestNetworkTest;

    RequestNetworkTest = QMessageBox::information(this, "Would you like to initiate a network test?",
        "Would you like to perform a network test?\n\nThe application will test the network for connectivity to and from the licensing server specified.\n\nResults will be displayed in the 'Log' tab.",
        QMessageBox::Yes | QMessageBox::No);

    QNetworkRequest req;

    QByteArray postData;

    QNetworkReply* reply;

    switch (RequestNetworkTest) {

    case QMessageBox::Yes:

        LoggingWidget->logText(tr("Beginning the network test."));

        if (UseSecuredURL) {

            req.setUrl(QUrl(SecureURL + "testconnection.php"));

            LoggingWidget->logText(tr("Connecting to secure URL: ") + SecureURL + tr("testconnection.php"));

        }
        else {

            req.setUrl(QUrl(UnsecureURL + "testconnection.php"));

            LoggingWidget->logText(tr("Connecting to unsecure URL: ") + UnsecureURL + tr("testconnection.php"));

        }

        MainNetConnector->setCookieJar(new QNetworkCookieJar(MainNetConnector));

        LoggingWidget->logText(tr("Cookie jar prepared for data to send."));

        reply = MainNetConnector->post(req, postData);

        LoggingWidget->logText(tr("Data sent."));

        connect(reply, &QNetworkReply::finished, this, &QTBasicWidget::processTestResults);
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(networkError(QNetworkReply::NetworkError)));

        if (TestingTimer) {

            TestingTimer->stop();
            TestingTimer->deleteLater();
            TestingTimer = NULL;

        }

        TestingTimer = new QTimer(this);
        connect(TestingTimer, SIGNAL(timeout()), this, SLOT(onDelayedNetworkTestReponse()));
        TestingTimer->start(5000);

        break;

    case QMessageBox::No:

        QMessageBox::information(this, "Test cancelled.",
            "Network test cancelled.",
            QMessageBox::Ok);

        break;

    default:

        QMessageBox::information(this, "Test cancelled.",
            "Network test cancelled.",
            QMessageBox::Ok);

        break;

    }

}

The function that received the results of the test:

void QTBasicWidget::processTestResults() {

    if (TestingTimer) {

        TestingTimer->stop();
        TestingTimer->deleteLater();
        TestingTimer = NULL;

    }

    LoggingWidget->logText(tr("Reply received."));
    auto reply = qobject_cast< QNetworkReply *>(sender());
    QByteArray bytes = reply->readAll();
    QString str = QString::fromUtf8(bytes.data(), bytes.size());

    LoggingWidget->logText(tr("Raw data from reply: ") + str);

    GLint statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

    LoggingWidget->logText(tr("Reply status code: ") + QString::number(statusCode));

    if (statusCode == 200) {

        QMessageBox::StandardButton NetworkTestResults;

        NetworkTestResults = QMessageBox::information(this, "Test succeeded!.",
            "Network test succeeded.",
            QMessageBox::Ok);

    }
    else {

        QMessageBox::StandardButton NetworkTestFailed;

        NetworkTestFailed = QMessageBox::critical(this, "Test failed!.",
            "Network test failed.",
            QMessageBox::Ok);

    }

}

And the error-handling function: void QTBasicWidget::networkError(QNetworkReply::NetworkError err) {

    if (CurrentlyDebugging) {

        LoggingWidget->logText(tr("Network error. Error code is: ") + QString::number(err));

    }

    QMessageBox::StandardButton CriticalMessageBox;

    CriticalMessageBox = QMessageBox::critical(this, tr("Licensing Server Error"),
        tr("Specific error code was (") + QString::number(err) + tr(")"), QMessageBox::Ok);

}

Upvotes: 1

Views: 5116

Answers (2)

slist
slist

Reputation: 51

Using "C:\Qt\MaintenanceTool.exe" Add or remove components In Qt > Developer and Designer Tool > OpenSSL x.y.z Toolkit

Copy all DLL from the following directory, in the directory of your EXE file. C:\Qt\Tools\OpenSSL\Win_x64\bin

Upvotes: 0

phyatt
phyatt

Reputation: 19112

http://doc.qt.io/qt-5/qtnetwork-downloadmanager-example.html

http://doc.qt.io/qt-5/qtnetwork-download-example.html

It looks like you probably should check for SSL errors, too.

Hopefully this is a consistent bug, that you can find what is going on. My best guess is that it is SSL related. The downloader examples show how to view these errors.

#ifndef QT_NO_SSL
    connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(sslErrors(QList<QSslError>)));
#endif

// ...

void DownloadManager::sslErrors(const QList<QSslError> &sslErrors)
{
#ifndef QT_NO_SSL
    foreach (const QSslError &error, sslErrors)
        fprintf(stderr, "SSL error: %s\n", qPrintable(error.errorString()));
#else
    Q_UNUSED(sslErrors);
#endif
}

Hope that helps.

Upvotes: 1

Related Questions