Unsolved Cannot get data from HTTP request
-
You should move the Qt 5 new syntax. It would have show you that error is not part of QNetworkAccessManager and that the signature of ssErrors is wrong.
-
@SGaist said in Cannot get data from HTTP request:
You should move the Qt 5 new syntax. It would have show you that error is not part of QNetworkAccessManager and that the signature of ssErrors is wrong.
Which syntax? I use Qt5.
I tried even:
QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(finished(reply)), this, SLOT(replyFinished(reply))); connect(reply, SIGNAL(error(reply)), this, SLOT(replyFinished(reply))); connect(reply, SIGNAL(sslErrors(reply)), this, SLOT(replyFinished(reply)));
-
@t0msk
Hi
The SIGNAL and SLOT macros is the "old way"
its explained here
https://wiki.qt.io/New_Signal_Slot_SyntaxThe main benefit is that it gives errors at compile time if its not correct.
The SIGNAL and SLOT will eat most things and not complain but simply
fail to work at runtime. -
So I tried this:
connect( reply, &reply::finished, this, &Manager::replyFinished );
And I get:
error: 'reply' is not a class, namespace, or enumeration
I quite don't understand what to put into &reply yet :)
-
The name of the class containing the signal, same goes for the last parameter, it's the name of the class containing the slot.
-
Changed it to this:
connect( reply, &QNetworkReply::finished, this, &Manager::replyFinished );
And I get:
/usr/include/qt/QtCore/qobject.h:243: error: static assertion failed: The slot requires more arguments than the signal provides. 243 | Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount), | ^~~~~~~~~~~~~~~~~
-
@t0msk said in Cannot get data from HTTP request:
QNetworkReply::finished,
Well you are mixing the classes/signals.
The reply's signals is
https://doc.qt.io/qt-5/qnetworkreply.html#finished
and have no QNetworkReply* parameter.so i think you mean
connect( Manager, &QNetworkAccessManager::finished, this, &Manager::replyFinished );
-
@mrjj said in Cannot get data from HTTP request:
@t0msk said in Cannot get data from HTTP request:
QNetworkReply::finished,
Well you are mixing the classes.
The reply signals is
https://doc.qt.io/qt-5/qnetworkreply.html#finished
and have no QNetworkReply* parameter.so i think you mean
connect( Manager, &QNetworkAccessManager::finished, this, &Manager::replyFinished );
Thank you,
so now I have:QSslConfiguration config = QSslConfiguration::defaultConfiguration(); config.setProtocol(QSsl::TlsV1_2); QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkRequest request; request.setHeader(QNetworkRequest::ServerHeader, "application/json"); request.setSslConfiguration(config); request.setUrl(QUrl("https://www.archlinux.org/packages/search/json/?q=dolphin")); QNetworkReply *reply = manager->get(request); connect( manager, &QNetworkAccessManager::finished, this, &Manager::replyFinished ); connect( manager, &QNetworkAccessManager::sslErrors, this, &Manager::replyFinished );
void Manager::replyFinished(QNetworkReply *reply) { qDebug() << reply->readAll(); QString ha = reply->readAll(); QString he; }
Still no output and no error :/
-
Hi
Its a bit odd to connect all to the same slot but lets leave it for now.now its time to
check your openSSL support !what does
qDebug() << "i can use HTTPS:" << QSslSocket::supportsSsl();
qDebug() << "version" << QSslSocket::sslLibraryBuildVersionString();say ?
-
@mrjj
It says:i can use HTTPS: true version "OpenSSL 1.1.1c 28 May 2019"
-
What version of Qt are you using ?
One more thing: do these connections prior to calling get.
-
@SGaist Qt version is 5.13.1
-
So where can be problem? :/
-
Did you move the connection statements as I suggested ?
-
@SGaist I dont know what do you mean
-
@SGaist wrote
Did you move the connection statements as I suggested ?
In your code you show:
QNetworkReply *reply = manager->get(request); connect( manager, &QNetworkAccessManager::finished, this, &Manager::replyFinished ); connect( manager, &QNetworkAccessManager::sslErrors, this, &Manager::replyFinished );
You are calling the
manager->get(request)
before you have connected the signals/slots onmanager
, which may/will be too late. He is asking you to change over anything like that toconnect( manager, &QNetworkAccessManager::finished, this, &Manager::replyFinished ); connect( manager, &QNetworkAccessManager::sslErrors, this, &Manager::replyFinished ); QNetworkReply *reply = manager->get(request);
so you move the connection statements to before the
get(request)
. So we get to see finished or quite possibly errors from the request. In general, you need to set up signals/slots as soon as you create an object (manager
here), before you call anything which could raise a signal. -
Changed it like:
connect( manager, &QNetworkAccessManager::finished, this, &Manager::replyFinished ); connect( manager, &QNetworkAccessManager::sslErrors, this, &Manager::replyFinished ); QNetworkReply *reply = manager->get(request);
and still doesn't work, no error, no reply.