Results 1 to 9 of 9

Thread: How to use Qhttp for downloading?? with the following code..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use Qhttp for downloading?? with the following code..

    Simplest way to download from the HTTP is below::

    Qt Code:
    1. connect(&http,SIGNAL(done(bool)),this,SLOT(httpdone())); //added in the constructor..
    To copy to clipboard, switch view to plain text mode 

    In the header file......Make the following changes...

    Qt Code:
    1. QHttp http;
    2. QFile file;
    3.  
    4. private slots:
    5. bool on_pushButton_clicked();
    6. void httpdone();
    7.  
    8. signals:
    9. void done();
    10.  
    11. in the Qthttp.cpp file...
    12.  
    13. bool QtHttp::on_pushButton_clicked()
    14. {
    15.  
    16. QString strUrl="http://www.blabla.com//file";
    17. QUrl url = QUrl::fromUserInput(strUrl);
    18.  
    19. QFileInfo fileInfo(url.path());
    20. QString strhost=url.encodedHost();
    21. QString filename=fileInfo.fileName();
    22. file.setFileName("C:\\Qt\\QHttp\\"+filename);
    23. http.setHost(url.host(),url.port(80));
    24. http.get(url.path(),&file);
    25.  
    26. if(!file.open(QIODevice::WriteOnly))
    27. {
    28. QMessageBox::warning(NULL,"warning","file is not opened",QMessageBox::Ok);
    29. }
    30. file.write(http.readAll());
    31. http.close();
    32. return true;
    33.  
    34. }
    35.  
    36. void QtHttp::httpdone()
    37. {
    38.  
    39. file.close();
    40. Q_EMIT done();
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 18th March 2011 at 12:52. Reason: missing [code] tags

Similar Threads

  1. About FTP uploading and downloading
    By prats in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2011, 11:28
  2. Downloading files
    By MTK358 in forum Newbie
    Replies: 3
    Last Post: 23rd June 2010, 00:08
  3. Replies: 11
    Last Post: 20th January 2009, 14:10
  4. Downloading from a clean url
    By travlr in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2007, 21:55
  5. QHTTP Status code
    By whoops.slo in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2006, 09:18

Tags for this Thread

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.