cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Progress function not being called...what's wrong?

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 26 Oct 2001 09:20:01 +0200 (MET DST)

On Thu, 25 Oct 2001, Mark Philip Erikson wrote:

> I can't seem to get the progress callback to work.

Hm, you're the second person this week who say this.

> I've got a QProgressBar widget in my main application widget that I'm
> trying to use inside of my progress callback. As far as I can tell, the
> progress callback isn't being called at all.

Well, I just tried running curl with the -# option to download stuff, and
that worked fine. It proves that it works at least partly!

> int progressFunction(void *ptr, size_t downTotalIn, size_t downNowIn,
> size_t upTotalOut, size_t upNowOut)
> {

[snip]

> return 1;
> }

Returning 1 from the progress function should cause it to abort the transfer
and return CURLE_ABORTED_BY_CALLBACK...

> curl_global_init(1<<1);

I'd suggest using the proper define for this...

> curlHandle = curl_easy_init();
> curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, &write_data);
> curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION,
> &progressFunction);
> curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, ProgressBar3);
> // ProgressBar3 is a QProgressBar*
>
> prepareDownload(currentDate);
> downloadFiles(currentDate, curlHandle);
> curl_easy_cleanup(curlHandle);
> curl_global_cleanup();
> }

I guess that downloadFiles() function calls curl_easy_perform() ?

> Comments: While the write_date function works as-is, I can't get
> progressFunction to work at all. I've tried prototyping it in my
> extern "C" block, passing a reference, not passing a reference, etc.
> I'm stuck.

It should be within an extern "C" block, and the C syntax for setting the
setopt would be similar to:

  curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION, progressFunction);

You're not setting CURLOPT_NOPROGRESS by any chance?

> Any ideas?

Run it through a debugger, set a break point in Curl_pgrsUpdate and
single-step through the function to see why it doesn't call your callback
(data->set.fprogress).

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2001-10-26