How to send arbitrary download request to proper handler
I'm building a Qt applica开发者_运维技巧tion and using the QNetworkAccessManager to manager my http requests. Due to the asyncronous nature of QNetworkAccessManager you have to bind a slot to recieve the QNetworkReply when it's done.
I'm new to multithreaded design so I'm not sure how to handle this. I will have 3 seperate types of network replies which need to be parsed in the bound slot and then passed to the correct handler. One will extract a link, the 2nd will extract a picture, and the third will parse a post request's reply to verify that it was successful. All of this takes place within a QWidget subclass.
So, I'm wondering how this is normally handled. As I see it, based purely on intuition as I've done little reading on this specific subject, I would think there are two ways to handle this. One would be to rebind the network manager's finished() signal depending on the call and the other would be to use some sort of state flags and check those to see what the reply is expected to be. What is the preferred method, not necessarily between these two, that's just all I could think of myself, someone more experienced may well have a better solution.
Now, I'm also fairly new to c++, so if the later is the better way what's the best way to handle flags in this case? Would I use a bitset, an enum/flag setting function, or something else? Thanks guys!
If you know the type of reply you're going to get as a result of doing specific request you can connect void QNetworkReply::finished () signal to suitable handler.
精彩评论