windows app for simle API get : TLS initialization failed
-
i have this error
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
i made this
qDebug()<<"\nSupport -------------------> "<< QSslSocket::supportsSsl() <<"\nLibraryBuildVersionS -------> "<< QSslSocket::sslLibraryBuildVersionString() <<"\nLibraryVersionS -----------> "<< QSslSocket::sslLibraryVersionString() <<"\nLibraryBuildVersionN ------> "<< QSslSocket::sslLibraryBuildVersionNumber() <<"\nLibraryVersionN -----------> "<< QSslSocket::sslLibraryVersionNumber();
his return this
Support -------------------> false LibraryBuildVersionS -------> "OpenSSL 1.1.1b 26 Feb 2019" LibraryVersionS -----------> "" LibraryBuildVersionN ------> 269488175 LibraryVersionN -----------> 0 qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
-
Hi and welcome to devnet,
What version of Qt are you using ?
On what platform ?
What version of OpenSSL do you have ?
How did you install it ? -
hi,
i use Qt 5.13.2
on windows 10
i don't learn ssl, into i don't know (it is certainly my probleme) -
What compiler are you using ?
You have to install OpenSSL 1.1 and it should be built with the same compiler you are using with Qt.
-
i use MinGW 64Bit
i've download a openssl.zip but i don't understand why install it ? -
Why ? Because Qt does not provide OpenSSL due to some international restriction. You have to provide OpenSSL yourself if your application need some it.
-
haa ok,
but how do we provide OpenSSL then?
Sorry about my lack of knowledge of the subject
Thank you very much. -
It's okay, I actually made it.
-
Everything is working ?
-
almost,
I'm getting to have my xml thong
but my "onmanagerfinished" method only runs after my on _button_clicked method.my constructor :
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); manager = new QNetworkAccessManager(); QObject::connect(manager,&QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { qDebug() << reply->errorString(); return; } answer = reply->readAll(); qDebug() << answer; });
but it's return this (qDebug())
#########################################OKbegin #########################################GetuuidBegin #########################################GetuuidEnd Answer ----> "" #########################################OKend UUID -------> "" "{\"id\":\"069a79f444e94726a5befca90e38aaf5\",\"name\":\"Notch\"}"
my methodes :
QString MainWindow::GetUUID(QString Pseudo) { qDebug()<<"\n#########################################GetuuidBegin"; QString str = "https://api.mojang.com/users/profiles/minecraft/" + Pseudo + "?at=" + getTimeStamp(); request.setUrl(QUrl(str)); manager->get(request); qDebug()<<"\n#########################################GetuuidEnd" <<"\nAnswer ----> "<< answer; return answer; }
void MainWindow::on_OK_clicked() { qDebug() <<"\n#########################################OKbegin"; QString UUID = GetUUID(ui->Speudo->text()); qDebug() <<"\n#########################################OKend" << "\nUUID ------->"<< UUID;
PS : what I call onManagerFinished is:
[=](QNetworkReply *reply) { if (reply->error()) { qDebug() << reply->errorString(); return; } answer = reply->readAll(); qDebug() << answer; }
because I used to use an onManagerFinished method instead
-
Your slot (well lambda in this case) will be called asynchronously at some point when the answer to the request is completely received. What you are doing now is calling your qDebug statement right after you made your request which is not yet done or might not even have been sent to the server yet.
-
yes I understand I only receive the answer when it is completely received, so I need to use reply.isFinished(), but where ? I'm not sure I understand how to use it (even with the doc)
-
@louis-cordhomme said in windows app for simle API get : TLS initialization failed:
reply.isFinished()
Hi
Consider just using signal and slot to solve this asynchronously.
(minwindow.h, define a new signal )signal:
void AnswerReady(QString Pseudo);then in your
QObject::connect(manager,&QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { qDebug() << reply->errorString(); return; } answer = reply->readAll(); qDebug() << answer; emit AnswerReady(answer); // tell the world });
then connect this new signal to lambda or slot where you do what ever you want to do with the
data
connect ( this,&Mainwindow::AnswerReady, this, &Mainwindow::ProcessAnswer);void MainWindow::ProcessAnswer(QString answer) { qDebug()<<"\n#########################################GetuuidEnd" <<"\nAnswer ----> "<< answer; }
-
Actually I'm going to have several different requests to make and I wanted to make methods like getUUID or getXXX
I'm not sure I understand how to use ProcessAnswer -
@louis-cordhomme
Hi
Well the QNetworkAccessManager is by nature asynchronous so you have to code to support that.one way to handle reading different data is to use member variables to keep the state in.
void MainWindow::ProcessAnswer(QString answer) {
if ( ReadingType == UUID)
// use answer for thatif ( ReadingType == SOMEOTHER)
// use answer for that
}Its also possible to connect to signal finished on the QNetworkReply and in that way know which request has which data.
I know you wish to do
NetworkAccessManager NAManager; QUrl url ("http://www.google.com"); QNetworkRequest request(url); QNetworkReply *reply = NAManager.get(request); QEventLoop eventLoop; QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit())); eventLoop.exec(); // it stays in here until its finished. std::cout << "finished" << std::endl; //request finished here
where is synchronous in nature and feels easier to code but its kinda bad design and should be avoided.
-
Is there a set of steps to follow one after the other ?
If so, you may want to consider using a state machine to model that.