Hello,
First, I understand that asynchronous QHttp API is usually the right way to go. However, I have a problem that is very sequential in nature, which makes any async. solution ugly.
Briefly, the problem is as following:
Fetch document R1, parse R1, depending on what's found fetch some document R2, parse R2, depending on what's found there, fetch and parse some document R3, etc.
There are two asynchronous approaches (using QHttp) I can come up with:
(1) Create one giant state machine (keep the current state in some member variable(s) and have bunch of switch statements) - UGLY.
(2) Create a separate class for every type of document R1, R2, R3, etc. - UGLY.
A much cleaner solution would be to create a sync. way of fetching documents via Http. Then, I would not need to further complicate already complicated logic. I could also place all sync code in a separate thread to keep the QT even loop running.
QUESTION: What is the best way to implement synchronous Http functionality? Al I can think of is something along the lines of:
requestId_ = qHttp_->get("http://google.com");
while(qHttp_->hasPendingRequests()) {
qApp->processEvents();
}
plus have a slot connected to the QHttp requestFinished() signal to copy whatever data is there when the requestId_ is finished...
Any better ideas?
Bookmarks