'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;
}
Solution 1:[1]
It took me literally an entire day to figure out how to make it working. I eventually found the answer here.
- In Qt maintenance tool select Qt > Developer and Designer Tools > OpenSSL 1.1.x Toolkit and install it
- Add the following in
.proINCLUDEPATH += C:/Qt/Tools/OpenSSL/Win_x86/include LIBS += -LC:/Qt/Tools/OpenSSL/Win_x86/bin -llibcrypto-1_1 -llibssl-1_1 - Copy
libcrypto-1_1.dllandlibssl-1_1.dllfromC:/Qt/Tools/OpenSSL/Win_x86/binwith your program
What took me the whole day was to find step 1.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
