Darkproduct
Darkproduct

Reputation: 1237

How to get Qt 5.8 working with OpenSSL on Windows

I am trying to get Qt 5.8 working with OpenSSL on Windows, but every time I get a step forward I hit another bigger object.

Edit/Update: This error occurs only in debug mode!

Here is my setup so far:

But here is the problem: Every time I had a connection open whether with SSL or not I get an error by quitting the application. Exception thrown at (ntdll.dll).

Error Message, Call Stack, ...

I tested my code with the Visual Leak Detector because I thought it was a Memory issue, but it does not solve my Problem. I rally have no clue where I should start anymore...

Here is a small example in Qt Creator 4.2.1 which doesn't work either

Here is my Code (it works fine with http, when I delete the OpenSSL dll's):

void InfoGatherer::getInfo(QString name)
{
    // TODO: Search for the name and select right page
    QUrl url = QUrl(name);
    data.clear();

    QNetworkRequest *request = new QNetworkRequest(url);
    request->setRawHeader("User-Agent", userAgent);

    if (name.startsWith("https"))
    {
        QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfiguration());
        sslConfiguration.setProtocol(QSsl::TlsV1_2OrLater);
        request->setSslConfiguration(sslConfiguration);
    }
    else
    {
        // TODO: Try to get https
    }

    reply = webCtrl->get(*request);

    connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));

    // Mem leaks (Visual Leak Detector)
    if(!name.startsWith("https"))
        webCtrl->deleteResource(*request);

    delete request;
}

void InfoGatherer::onReadyRead()
{
    data.append(reply->readAll());
}

void InfoGatherer::slotError(QNetworkReply::NetworkError)
{
    // TODO
    qWarning() << "ErrorNo: " << reply->error() << "for url: " << reply->url().toString();
    qDebug() << "Request failed, " << reply->errorString();
    qDebug() << "Headers:" << reply->rawHeaderList() << "content:" << reply->readAll();
}

void InfoGatherer::onReplyFinished()
{
    QString html = QString(data);

    emit got_webpage(&html);
}

Qt detects the OpenSSL library correctly:

qDebug() << "Support SSL:  " << QSslSocket::supportsSsl()
        << "\nLib Version Number: " << QSslSocket::sslLibraryVersionNumber()
        << "\nLib Version String: " << QSslSocket::sslLibraryVersionString()
        << "\nLib Build Version Number: " << QSslSocket::sslLibraryBuildVersionNumber()
        << "\nLib Build Version String: " << QSslSocket::sslLibraryBuildVersionString();

Upvotes: 1

Views: 2637

Answers (3)

0x2648
0x2648

Reputation: 83

Maybe you could try the prebuild Windows binaries for OpenSSL from slproweb.com. Also it seems that Qt 5.8 needs OpenSSL v1.0.2 to work properly.

Upvotes: 2

Darkproduct
Darkproduct

Reputation: 1237

Solution:

Build all dll's from OpenSSL again and dont forget to build the debug dll's.

Here is a very good link how to build the dll's. Build the 64 Bit normal and debug Version!

From the Footnotes use: - nmake -f ms\ntdll.mak (install) to get the dll's

And don't rename dll's to libeay64.dll and ssleay64.dll.

Upvotes: 1

Joseph D.
Joseph D.

Reputation: 12174

This works for me. Just a local variable for request.

QUrl imageUrl = QUrl (link);
QNetworkRequest request (imageUrl);

/* SSL Configuration */
QSslConfiguration sslConfiguration = request.sslConfiguration();
sslConfiguration.setPeerVerifyMode (QSslSocket::VerifyNone);
sslConfiguration.setProtocol (QSsl::AnyProtocol);
request.setSslConfiguration (sslConfiguration);
networkAccessMgr->get (request);
  • Verify Peer Mode: QSslSocket::VerifyNone
  • Protocol: QSsl::AnyProtocol

Upvotes: 0

Related Questions