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)
#define USE_SHA1
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?