curl-library
Progress function not being called...what's wrong?
Date: Thu, 25 Oct 2001 23:04:40 -0400
Hi, folks. I'm currently using QT 2.3 Non-Commercial to write a small
application to download web comics. I managed to get the write
function working, but I can't seem to get the progress callback to
work. 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.
Relevant code:
int progressFunction(void *ptr, size_t downTotalIn, size_t downNowIn,
size_t upTotalOut, size_t upNowOut)
{
static int first_time = 1;
QProgressBar *progressBar = (QProgressBar *)ptr;
int downloadTotal = static_cast< int >(downTotalIn);
if(first_time == 1)
{
first_time = 0;
progressBar->setTotalSteps(2500);
progressBar->setProgress(0);
}
progressBar->setProgress(1250); // Just to prove the
function's being called
return 1;
}
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
static int first_time=1;
static FILE *outfile = stream;
size_t written;
if (outfile == NULL)
{
return -1;
}
written = fwrite(ptr,size,nmemb,outfile);
return written;
}
void windowimpl::downloadSequence()
{
...
curl_global_init(1<<1);
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();
}
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 all compiles fine, but it does NOTHING. VC++
recognizes if, say, I change my cast from a QProgressBar to a
QLineEdit, as it promptly informs me that those aren't member
functions, so at least the compiler says I'm on the right track. But
yeah, the progress function isn't getting called as far as I can tell.
Any ideas?
Mark Erikson
- TEXT/HTML attachment: TEXT.htm