dimkanovikov / WebLoader

High level wrapper around QNetworkAccessManager for make network communications easy
GNU Lesser General Public License v3.0
17 stars 6 forks source link

Got "not captured" issue when using loadAsync api #5

Closed xeoshow closed 8 years ago

xeoshow commented 8 years ago

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); }

dimkanovikov commented 8 years ago

Hi!

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).

xeoshow commented 8 years ago

Thanks! Never used lambda before. :-D