PDA

View Full Version : Remove signal?



ttimt
30th March 2015, 17:52
I want my app to login to a site, but first it needs to go to the mainpage and get a session id.



QNetworkAccessManager *manager = new QNetworkAccessManager;
QNetworkRequest request;
request.setUrl(furl);

//SIGNAL SLOT
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(Getreply(QNetworkReply*)));

manager->get(request);

And then I get the session ID at the Getreply slot. Next, I need to post data, username and password.



void Getreply()
{
//Edit parameters, url etc....
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(Getlogin(QNetworkReply*)));

manager->post(request)
}


Getlogin will have codes like check if login success and so on..


This first problem is, when the manager signal emits finished(QNetworkReply*) in Getreply(), I believe not only Getlogin will run, but also Getreply, because both are now connected signal slots. How can I turn the first "connect" off, or what other solution can I have.

Second, I created all the variables on the first function, but then I need to edit stuff like post data at the second function, Getreply, i'm forced to make them global. Any other ways?

Thx.

anda_skoa
30th March 2015, 18:35
You can disconnect() the same way you connect().

You can check the slot argument and return if it is not the one you want to handle in a given slot.

You can connect to the QNetworkReply's finished() signal and only get your slot invoked when that particular request finished.

You don't need global variables, just put the manager into a member of the class that has these methods or access the manager from the QNetworkReply object

Cheers,
_

ttimt
30th March 2015, 19:00
You can check the slot argument and return if it is not the one you want to handle in a given slot.
_
You mean since I know what data to expect, I can verify it?

Then if I have codes below manager->post, those might be executed before slot returns. I can use QEventloop rite.




You can connect to the QNetworkReply's finished() signal and only get your slot invoked when that particular request finished.
_
I can connect finished() to the two slot() and invoke one of them?:confused: can you explain further? or example.. thankss

jefftee
30th March 2015, 19:35
Here's how I handle this... I use the QNetworkAccessManager::finished signal to log all HTTP results, period. I then connect the individual QNetworkReply::finished signal to manage the results of the request.

So QNetworkAccessManager::finished is used only for logging the request's status and all processing handled in the individual request/reply finished signals.

If you only care about managing the reply, then I recommend you use the reply pointer returned by QNetworkRequest and connect a slot to the &QNetworkReply::finished signal.

Hope that helps.

anda_skoa
31st March 2015, 06:58
You mean since I know what data to expect, I can verify it?

The signal transports the QNetworkReply object that was finished, which allows you to access the QNetworkRequest that was used to create it.
So you could check the URL, for example.



Then if I have codes below manager->post, those might be executed before slot returns. I can use QEventloop rite.

Why would you want to do that?



I can connect finished() to the two slot() and invoke one of them?:confused: can you explain further? or example.. thankss
Why do you want to connect to two slots when you want one to be invoked?
That kind of defeats your goal, doesn't it?

I.e. what would you gain from connecting the finished() signal of the first request to the slot handling the second one?

Cheers,
_

ttimt
31st March 2015, 14:36
The signal transports the QNetworkReply object that was finished, which allows you to access the QNetworkRequest that was used to create it.
So you could check the URL, for example.


Why would you want to do that?


Why do you want to connect to two slots when you want one to be invoked?
That kind of defeats your goal, doesn't it?

I.e. what would you gain from connecting the finished() signal of the first request to the slot handling the second one?

Cheers,
_
Okay thanks :)
I'm now using "disconnect"