TLS initialization failed
-
Hello! While I was programming in Qt (on Windows 10) I stuck with a problem:
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
I downloaded 1.1.1d of OpenSSL, also included OpenSSL-Win32 in PATH, then I tried to include
INCLUDEPATH += C:/Program Files (x86)/OpenSSL-Win32/include
And nothing have helped me!
My code:
/... #include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkRequest> #include <QtXml/QDomDocument> #include <QtXml/QDomNode> #include <QUrl> /... void log_in::setCurrency() { QNetworkAccessManager *manager = new QNetworkAccessManager(this); QNetworkRequest request(QUrl("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")); connect(manager, &QNetworkAccessManager::finished, this, &log_in::getResponse); qDebug() << QSslSocket::sslLibraryBuildVersionString(); manager->get(QNetworkRequest(request)); } void log_in::getResponse(QNetworkReply *reply) { QDomDocument domDoc; if(domDoc.setContent(reply->readAll())) { QDomNode rootNode = domDoc.documentElement(); findNode( rootNode, "Cube", "USD"); findNode( rootNode, "Cube", "RUB"); findNode( rootNode, "Cube", "GBP"); } delete reply; } bool log_in::findNode(const QDomNode &node, const QString &name, const QString ¤cy) { if(node.isElement()) { QDomElement element = node.toElement(); if(element.tagName() == name && element.attribute("currency") == currency) { QString str; str.append(node.firstChildElement("currency").text()); str.append(" "); QString str_double(node.firstChildElement("Cube rate").text()); double rate = str_double.toDouble(); str.append(QString::number(rate, 'f', 2)); str.append(" €"); if(currency == "USD") { ui->dollar_currency->setText(str); } else if(currency == "RUB") { ui->rubles_currency->setText(str); } else if(currency == "GBP") { ui->pounds_currency->setText(str); } return true; } } QDomNode siblingNode = node.nextSiblingElement(); while(!siblingNode.isNull()) { bool res = findNode(siblingNode, name, currency); if(res) return true; siblingNode = node.nextSiblingElement(); } QDomNode childNode = node.firstChild(); if(!childNode.isNull()) { bool res = findNode(childNode, name, currency); if(res) return true; } return false; }
I would like to get help from you.
-
Hi and welcome to devnet,
What version of Qt are you using ?
Which compiler are you using ? -
Then you should double check, because you have to get an OpenSSL build that uses the same compiler.
-
Then you should double check, because you have to get an OpenSSL build that uses the same compiler.
-
In the Run part of the Project panel, did you also modify the PATH environment variable so the OpenSSL dlls can be found ?
Do not do that system wide.
-
In the Run part of the Project panel, did you also modify the PATH environment variable so the OpenSSL dlls can be found ?
Do not do that system wide.
-
Unfold the Run Environment part, you'll have there the variables you can modify.
-
I meant click on the "Details" arrow under Run Environment.
-
@Sahak After you selected the
Path
variable, you can usePrepend Path
to add the path to the libraries (DLLs) to yourPath
variable. Then at runtime, this directory searched when the DLLs are loaded.Regards
-
You application seems to crash, what do you get if running it through the debugger ?