PDA

View Full Version : Libcurl messes up the order of execution



phoenix12345
6th September 2010, 22:27
Hello,

I have a program that downloads some XML files off the web and i used QT to implement a minimalistic GUI for it. For the transfer part i decided to use libcurl, since i just began programming with QT and didn't knew about QHttp and i used libcurl in the past for http transfers.

Whilst implementing a progress bar i ran into some problems, that are apparently caused by libcurl. I wanted to display the progress bar widget and then start downloading the XML files, but it happened the other way around. That is libcurl started to download the file and the progress bar appeared only after the files were downloaded. I managed to replicate the same problem with a small project and attached it here.

I will eventually switch to QHttp since it's simpler to use and suits my problem just fine, but i'm dying of curiosity as to why this happens.

tbscope
7th September 2010, 05:24
Most likely this happens because the main thread gets blocked by downloading the file and doesn't have enough time to handle the events in the eventloop.
Therefor, the actual displaying of the widget and/or updating of the statusbar happens when the eventloop gets enough time.

How to work around this:
1. Use asynchronous sockets, this means a socket that doesn't block the event loop but instead makes use of the event loop
2. Put all the downloading into a separate thread.

phoenix12345
7th September 2010, 11:14
Thank you very much for your suggestions. I had a hunch that using a separate thread for downloading will be the solution to my problem but i was unsure and i just wanted to keep things sequential.