Cannot get data from HTTP request
-
The name of the class containing the signal, same goes for the last parameter, it's the name of the class containing the slot.
-
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), | ^~~~~~~~~~~~~~~~~
-
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 );
-
@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 ?
-
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 ?
-
What version of Qt are you using ?
One more thing: do these connections prior to calling get.
-
What version of Qt are you using ?
One more thing: do these connections prior to calling get.
-
Did you move the connection statements as I suggested ?
-
@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.