Pass pointer over QNetworkReply slot
-
I have a class called
Resolvermethod that is calledhandleResult(Result *result).
The classResulthas a member that is aQUrland others.
ThishandleResultmethod creates a request using the url from theresultpointer and connects theQNetworkReplysignal tohandlePage.
The thing here is that I need thatresultpointer in thehandlePageslot as well so I can modify the members in there.
Beforehand, I can't put theResultas a member ofResolvercause thehandleResultis being called several times, meaning that it won't probably be the rightResultwhenhandlePageis called (asQNetworkAccessManageris async).
So how can I pass that pointer tohandlePage? -
I have a class called
Resolvermethod that is calledhandleResult(Result *result).
The classResulthas a member that is aQUrland others.
ThishandleResultmethod creates a request using the url from theresultpointer and connects theQNetworkReplysignal tohandlePage.
The thing here is that I need thatresultpointer in thehandlePageslot as well so I can modify the members in there.
Beforehand, I can't put theResultas a member ofResolvercause thehandleResultis being called several times, meaning that it won't probably be the rightResultwhenhandlePageis called (asQNetworkAccessManageris async).
So how can I pass that pointer tohandlePage?@Mr-Gisa
can you show some code? Especially where you create the network reply and connect it to handlePage().
I guess the easiest would probably be to connect the network reply to a lambda slot and capture all the pointers/data you need. -
std::function. for example:void handlePage(QNetworkReply* sender, Result *result);connect(reply,&QNetworkReply::finished,this,std::bind(&MyClass::handlePage,this,reply,result));you need to make sure result doesn't get deleted in the meantime though
-
std::function. for example:void handlePage(QNetworkReply* sender, Result *result);connect(reply,&QNetworkReply::finished,this,std::bind(&MyClass::handlePage,this,reply,result));you need to make sure result doesn't get deleted in the meantime though
to add up to @VRonin the lambda approach:
QNetworkReply* reply = ... Result* result = ... connect( reply, &QNetworkReply::finished, this, [this, reply, result]() { // do whatever you have to do directly in here or call "this->handleResult(reply, result);" delete reply; delete result; });