Results 1 to 3 of 3

Thread: Downloading a page with QNetworkAccessManager

  1. #1
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Downloading a page with QNetworkAccessManager

    Hello,

    I'm trying to download a webpage using the QNetworkAccessManager but I always get strange build errors..

    Here is my code:
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "downloadpage.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. DownloadPage downloadPage;
    9. downloadPage.startDownload();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef DOWNLOADPAGE_H
    2. #define DOWNLOADPAGE_H
    3.  
    4. #include <Qt/QtNetwork>
    5. #include <QDebug>
    6.  
    7. class DownloadPage:QObject
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. DownloadPage();
    13. void startDownload();
    14.  
    15. private slots:
    16. void downloadComplete(QNetworkReply *reply);
    17.  
    18. private:
    19. QNetworkAccessManager *manager;
    20. };
    21.  
    22. #endif // DOWNLOADPAGE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "downloadpage.h"
    2.  
    3. DownloadPage::DownloadPage()
    4. {
    5. qDebug()<<"Download Page constructor called";
    6. manager = new QNetworkAccessManager(this);
    7. connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(downloadComplete(QNetworkReply*)));
    8. }
    9.  
    10. void DownloadPage::startDownload(){
    11. qDebug()<<"Downloading Page...";
    12. manager->get(QNetworkRequest(QUrl("http://www.google.ch")));
    13. qDebug()<<"Page call end but not finished yet";
    14. }
    15.  
    16. void DownloadPage::downloadComplete(QNetworkReply *reply){
    17. qDebug()<<"Page call finished";
    18. }
    To copy to clipboard, switch view to plain text mode 

    and my build errors are:
    Qt Code:
    1. debug/downloadpage.o: In function `DownloadPage':
    2. D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:6: undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject'
    3. D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:6: undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject'
    4. debug/downloadpage.o:D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:12: undefined reference to `_imp___ZN15QNetworkRequestC1ERK4QUrl'
    5. debug/downloadpage.o:D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:12: undefined reference to `_imp___ZN21QNetworkAccessManager3getERK15QNetworkRequest'
    6. debug/downloadpage.o:D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:12: undefined reference to `_imp___ZN15QNetworkRequestD1Ev'
    7. debug/downloadpage.o:D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:12: undefined reference to `_imp___ZN15QNetworkRequestD1Ev'
    8. collect2: ld returned 1 exit status
    9. mingw32-make.exe[1]: *** [debug\ComeOn.exe] Error 1
    10. mingw32-make.exe: *** [debug] Error 2
    11. 21:36:03: The process "D:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    12. Error while building project ComeOn (target: Desktop)
    13. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    Does anybody have an idea?

    Thanks!

  2. #2
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Downloading a page with QNetworkAccessManager

    Just add
    Qt Code:
    1. QT += network
    To copy to clipboard, switch view to plain text mode 
    in your .pro file

  3. The following user says thank you to Rhayader for this useful post:

    TempleClause (1st October 2012)

  4. #3
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Downloading a page with QNetworkAccessManager

    many many thanks!

Similar Threads

  1. Replies: 2
    Last Post: 12th December 2011, 22:29
  2. Load a simple Page after the Main Page.
    By mrhevor in forum Qt Quick
    Replies: 1
    Last Post: 27th September 2011, 11:32
  3. QWebView page loading fails after file downloading
    By mentalmushroom in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2011, 15:57
  4. Downloading multiple files using QNetworkAccessManager
    By aurorius in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2009, 11:51
  5. QTabWidget remove a page at the page's request
    By thomaspu in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2007, 21:45

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.