简体   繁体   中英

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:

  • Installed Qt 5.8
  • Downloaded and compiled version of OpenSSL
  • Transfer the small test project to MSVS2015
  • Copied dll files (libeay32.dll and ssleay32.dll) to the application Directory
  • SSL connection is now working fine

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).

错误消息,调用堆栈,...

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();
  • Support SSL: true
  • Lib Version Number: 268443791
  • Lib Version String: "OpenSSL 1.0.2h 3 May 2016"
  • Lib Build Version Number: 268443791
  • Lib Build Version String: "OpenSSL 1.0.2h 3 May 2016"

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.

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\\nt dll .mak (install) to get the dll's

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM