Results 1 to 20 of 28

Thread: How to download a file using HTTP with URL in QT?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 How to download a file using HTTP with URL in QT?

    Qt Code:
    1. QUrl url = QUrl::fromUserInput(strUrl);
    2. QFileInfo fileInfo(url.path());
    3. QString fileName=fileInfo.fileName();
    4. if (QFile::exists(fileName)) {
    5. QMessageBox::information(this, tr("HTTP"),
    6. tr("There already exists a file called %1 in "
    7. "the current directory.")
    8. .arg(fileName));
    9. }
    10.  
    11. file = new QFile(fileName);
    12. if (!file->open(QIODevice::WriteOnly)) {
    13. QMessageBox::information(this, tr("HTTP"),
    14. tr("Unable to save the file %1: %2.")
    15. .arg(fileName).arg(file->errorString()));
    16. delete file;
    17. file = 0;
    18. }
    19.  
    20. file.setFileName(fileName);
    21. file.open(QIODevice::WriteOnly);
    22. QHttp *http;
    23. http=new QHttp(this);
    24. setHost(url.host(),QHttp::ConnectionModeHttp);
    To copy to clipboard, switch view to plain text mode 


    Am getting while using the HTTP . It says undefined reference to the http object.
    I just want to download a file from the host.
    Last edited by wysota; 8th March 2011 at 08:26. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to download a file using HTTP with URL in QT?

    What include files have you specified?

  3. #3
    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 download a file using HTTP with URL in QT?

    I have included <QNetworkAccessManager>, <QHttp>

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to download a file using HTTP with URL in QT?

    And you have no other errors during compilation ? Do you have Qt += network in .pro file ?

  5. #5
    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 download a file using HTTP with URL in QT?

    No. I dont have errors. And also no Qt +=network in my .pro file.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to download a file using HTTP with URL in QT?

    And also no Qt +=network in my .pro file
    So add it

  7. #7
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to download a file using HTTP with URL in QT?

    Well if u want to work with network u have to have the Qt += network

Similar Threads

  1. HTTP pause download in QTCreator
    By nhs_0702 in forum Qt Programming
    Replies: 12
    Last Post: 29th November 2010, 14:24
  2. Download file to QString
    By Chiggins in forum Qt Programming
    Replies: 2
    Last Post: 25th June 2010, 19:16
  3. I want to download a piece of file?
    By mismael85 in forum General Programming
    Replies: 1
    Last Post: 27th February 2010, 15:35
  4. Download File
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2010, 09:53
  5. Download via HTTP in several threads?
    By bjilly in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2009, 14:15

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.