I am just trying below api to wrap a little, and want to LOG the input urlStr and jsonData in the callback, while got error when compiling, how to deal with such problem? Thanks again!
You have some troubles in your lambda. You need to capture urlStr and jsonData in lambda. For more info how you can do it see c++ reference (this for example).
Hello,
I am just trying below api to wrap a little, and want to LOG the input urlStr and jsonData in the callback, while got error when compiling, how to deal with such problem? Thanks again!
C:\util\global.cpp:133: error: 'urlStr' is not captured LOG(TRACE) << "urlStr=" << urlStr << ", jsonData=" << jsonData << ", replyData=" << replyData; ^ C:\util\global.cpp:133: error: 'jsonData' is not captured LOG(TRACE) << "urlStr=" << urlStr << ", jsonData=" << jsonData << ", replyData=" << replyData; ^
void Global::postJsonDataToCloud(const QString urlStr, const QString jsonData) { NetworkRequest *request = new NetworkRequest(); request->setRequestMethod(NetworkRequest::Post); request->setRawRequest(jsonData.toUtf8(), "application/json"); connect(request, &NetworkRequest::downloadComplete, [] (const QByteArray& replyData) { LOG(TRACE) << "urlStr=" << urlStr << ", jsonData=" << jsonData << ", replyData=" << replyData; }); request->loadAsync(urlStr); }