Closed xeoshow closed 8 years ago
I am trying to combine below two : NetworkRequestLoader::loadAsync(thousandsUrls, [](const QByteArray& _loadedData, const QUrl& _fromUrl) { qDebug() << "Loaded" << _loadedData.size() << "bytes from" << _fromUrl; });
NetworkRequest request; requset.setRequestMethod(NetworkRequest::Post); request.setRawRequest("{ \"method\": \"getUsers\" }", "application/json"); const QByteArray usersJson = request.loadSync("https://site.com/API/v2/function/");
Hi,
1) NetworkRequestLoader is a helper to simplify some often used cases. NetworkRequest directly not support this interface. You need doing something like this:
connect(request, &NetworkRequest::downloadComplete, [] (const QByteArray& replyData) {
LOG(TRACE) << "replyData=" << replyData;
});
2) There is a bad idea to use asynchronous loading method from instance of NetworkRequest on stack. When program will be out of scope in your code NetworkRequest will be destroyed and you'll never get a reply. Better to use dynamically created instance of NetworkRequest like this:
NetworkRequest* request = new NetworkRequest(parent);
request->setRequestMethod(NetworkRequest::Post);
request->setRawRequest(postJsonData.toUtf8(), "application/json");
connect(request, &NetworkRequest::downloadComplete, [] (const QByteArray& replyData) {
LOG(TRACE) << "replyData=" << replyData;
});
request->loadAsync("http://www.webforgood.com/api/v2/updatecloudconfig");
works great! Thanks v much! Really easy to use and lightweight lib for qt! Hope the comments for code could be translated into English as well! :-D
Thanks for feedback, @xeoshow. Maybe in someday :D
Hello, I am trying to write below code:
But got this error, anything I did wrong? Or just not supported? Thanks! D:\gitrepository\ui-desktop\mainwindow.cpp:572: error: no matching function for call to 'NetworkRequest::loadAsync(const char [47], MainWindow::nativeEvent(const QByteArray&, void, long int)::<lambda(const QByteArray&)>)' });