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. Load OpenSSL library and use QNetworkAccessManager makes application crash

Load OpenSSL library and use QNetworkAccessManager makes application crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
opensslqnetwork
5 Posts 3 Posters 2.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.
  • Kalay_JY99K Offline
    Kalay_JY99K Offline
    Kalay_JY99
    wrote on last edited by
    #1

    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());
    
        BIO_free(bio);
    
        return true;
    }
    #endif
    
    
    int main() {
        QNetworkAccessManager* manager = new QNetworkAccessManager();
    
        QNetworkRequest request;
        request.setUrl(QUrl("http:\\192.168.0.1"));
        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)
        validateLicense();
    #endif
    }
    

    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?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

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

        Hi,

        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.

        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
        1
        • Kalay_JY99K Offline
          Kalay_JY99K Offline
          Kalay_JY99
          wrote on last edited by
          #4

          Hi.

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

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

            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.

            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

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved