Reputation: 3223
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
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
Reputation: 3223
It took me literally an entire day to figure out how to make it working. I eventually found the answer here.
.pro
INCLUDEPATH += C:/Qt/Tools/OpenSSL/Win_x86/include
LIBS += -LC:/Qt/Tools/OpenSSL/Win_x86/bin -llibcrypto-1_1 -llibssl-1_1
libcrypto-1_1.dll
and libssl-1_1.dll
from C:/Qt/Tools/OpenSSL/Win_x86/bin
with your programWhat took me the whole day was to find step 1.
Upvotes: 1