Solved Read Data From URL
-
@jsulm
I am remove this lineevent.exec();
from my code And makeQNetworkAccessManager manager;
variable as a class member
but still i didn't the the response. -
@Ketan__Patel__0011 Do you mean finished signal was not emitted?
You should add error handling to your code.
And you CAN'T read the response just after sending the request, do it in a slot connected to finished signal... -
response->errorString()
function give me this error message
Error Is : Unknown error -
@Ketan__Patel__0011 As I said: you can't read response just after sending request. This is not how asynchronous APIs work. Read response in a slot connected ti finished signal. This is also what @JonB already wrote.
-
Thanks For Reply
So Do you have any Suggestion or Any Sample Code Or Any Block Of Code For it
-
@Ketan__Patel__0011 Did you read the documentation? https://doc.qt.io/qt-5/qnetworkaccessmanager.html
QNetworkAccessManager *manager = new QNetworkAccessManager(this); connect(manager, &QNetworkAccessManager::finished, this, &MyClass::replyFinished); manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
In MyClass::replyFinished you read the response.
And there are many examples: https://doc.qt.io/qt-5/examples-network.html
-
Thanks for the reply
I am try all are the solution
And Create One Small QWidget Application Example For it and my problem is solved but..
i am create one library in Qt any put my same code in my Class library functions
that time i didn't get the response from my URL. -
@Ketan__Patel__0011 In what app do you use that library? Does that app have a running Qt event loop?
-
Actually i am create My Library in QT And i am export The Some Function From My Library and used in others application (DLLImport And DLLExport)
-
@Ketan__Patel__0011 But does this application have a Qt event loop?
-
@jsulm
No that Application is not Qt Based But My Library Is Qt Based -
@Ketan__Patel__0011 said in Read Data From URL:
But My Library Is Qt Based
That is clear. But without Qt event loop Qt networking isn't going to work. You could execute networking part (from your DLL) in a thread with Qt event loop.