Qt World Summit: Submit your Presentation

Load OpenSSL library and use QNetworkAccessManager makes application crash

  • Hi.

    I am working with Qt 5.2. I am using QNetworkAccessManager to make some posts to a web (without encryption). Now I have to verify a signature of message (That message has nothing to do with the post and QNetworkAccessManager, they are completly separated).

    Both parts of code work fine separately, but when they come together the application crashes. If I add the OpenSSL to the application and I call a QNetworkAccessManager::post then it fails. The program pointer is in OPENSSL_sk_pop_free and it crashes after a QNetworkAccessManager::post call.

    The code:

    //#define OPENSSL
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <openssl/bio.h>
    #if defined(OPENSSL)
    bool validateLicense()
        BIO* bio = BIO_new(BIO_s_mem());
        return true;
    int main() {
        QNetworkAccessManager* manager = new QNetworkAccessManager();
        QNetworkRequest request;
        request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
        QString com("{\"hello world\"}");
        QByteArray data(com.toLocal8Bit());
        qDebug() << Q_FUNC_INFO << "data to POST" << com;
        manager->post(request, data);
    #if defined(OPENSSL)

    The .pro file:

    QT += core network
    QT -= gui
    CONFIG += c++11
    TARGET = console
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    # libcrypto
    LIBS += $$[OPENSSL_INSTALL_ROOT]/libcrypto.a

    If I uncomment the #define OPENSSL the application crashes in line manager->post(request, data);.

    How can I disable the OpenSSL in QNetworkAccessManager to avoid the application crash?

  • Qt Champions 2017

    It may be issue with OpenSSL version compatibility. Qt may be looking for older version of OpenSSL library.

  • Lifetime Qt Champion


    The first thing you should do is create a QCoreApplication object before trying to use QNetworkAccessManager.

    What is currently happening is that you are trying to use the Qt network stack without its internals initialised.

  • Hi.

    @SGaist in the real application I have an QCoreApplication, this is just a minimal example.

  • Lifetime Qt Champion

    The problem with such an example is that it doesn't allow to replicate your problem correctly and triggers others that are not related to yours thus it's not possible to offer sensible help.

Log in to reply