Results 1 to 6 of 6

Thread: Problem with curl writefunction

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Location
    Kraków / Poland
    Posts
    32
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Problem with curl writefunction

    Hello.
    I have little problem.
    I have functions:
    Qt Code:
    1. size_t WriteData(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    2. size_t written;
    3. written = fwrite(ptr, size, nmemb, stream);
    4. return written;
    5. }
    6. int MainWindow::progress_func(void* ptr, double TotalToDownload, double NowDownloaded, double TotalToUpload, double NowUploaded)
    7. {
    8. ui->progressBar->setMaximum(TotalToDownload);
    9. ui->progressBar->setValue(NowDownloaded);
    10. double speed;
    11. curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed);
    12. ui->label_2->setText(QString("Prędkość: %0").arg(speed));
    13. return NowDownloaded;
    14. }
    15. bool MainWindow::downloadFile(QString url, QString filename)
    16. {
    17. FILE *fp;
    18. fp = fopen(filename.toStdString().c_str(), "wb");
    19. ui->label->setText(filename);
    20. ui->label_2->setText("Predkosc: 0 KB/s");
    21. curl = curl_easy_init();
    22. curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1);
    23. curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    24. curl_easy_setopt(curl, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (compatible;)");
    25. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
    26. curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
    27. curl_easy_setopt(curl, CURLOPT_HEADER, 1);
    28. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteData);
    29. curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    30. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    31. curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
    32. curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
    33. curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
    34. curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, &MainWindow::progress_func);
    35. curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
    36. status = curl_easy_perform(curl);
    37. if(status !=0)
    38. qDebug() << QString("curl_easy_perform() error: %0").arg(curl_easy_strerror(status));
    39. curl_easy_cleanup(curl);
    40. fclose(fp);
    41. return true;
    42. }
    To copy to clipboard, switch view to plain text mode 
    When I try to download a file, window of my aplication is frozen(?) until downloading is not finished.
    Could you suggest what could I do to make this work?
    Sory for my bad english
    Janusz
    Last edited by januszmk; 26th July 2011 at 15:48.

Similar Threads

  1. Curl in QT Creator
    By januszmk in forum Newbie
    Replies: 10
    Last Post: 25th August 2011, 23:14
  2. cURL & QWebKit don't mix
    By Frankenstein Coder in forum Newbie
    Replies: 1
    Last Post: 20th July 2011, 03:03
  3. cURL With Qt Creator [Windows and Linux]
    By Chiggins in forum Qt Tools
    Replies: 1
    Last Post: 24th June 2010, 08:29
  4. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.