JRR
JRR

Reputation: 3223

QNetworkAccessManager does not work on windows with https

I'm trying to download files from a https url with my application using the following code in Qt5. This works perfectly as I want on Linux but with the Windows version content is always empty and consequently the exception is thrown.

According to comments and research it seems to be related to SSL

void FileDownloader::download(QString url, QString dest)
{
    QNetworkAccessManager manager;
    QNetworkReply *response = manager.get(QNetworkRequest(QUrl(url)));
    QEventLoop event;
    connect(response, SIGNAL(finished()), &event, SLOT(quit()));
    event.exec();
    QByteArray content = response->readAll();

    if (content.isEmpty())
        throw std::logic_error((QString("Impossible to download url : ") + url).toStdString());

    QSaveFile file(dest);
    file.open(QIODevice::WriteOnly);
    file.write(content);
    file.commit();
    return;
}

Upvotes: 0

Views: 1035

Answers (2)

Magdalena
Magdalena

Reputation: 1

just as ciobi says it seems that copying these dll is enough I was downloading file, worked under linux and under windows IDE, outside the IDE QNetworkReply::readAll had zero length I used reply->ignoreSslErrors(); but it didn't helped

Upvotes: -1

JRR
JRR

Reputation: 3223

It took me literally an entire day to figure out how to make it working. I eventually found the answer here.

  1. In Qt maintenance tool select Qt > Developer and Designer Tools > OpenSSL 1.1.x Toolkit and install it
  2. Add the following in .pro
    INCLUDEPATH += C:/Qt/Tools/OpenSSL/Win_x86/include
    LIBS += -LC:/Qt/Tools/OpenSSL/Win_x86/bin -llibcrypto-1_1 -llibssl-1_1
    
  3. Copy libcrypto-1_1.dll and libssl-1_1.dll from C:/Qt/Tools/OpenSSL/Win_x86/bin with your program

What took me the whole day was to find step 1.

Upvotes: 1

Related Questions