Hello,
I'm trying to download a webpage using the QNetworkAccessManager but I always get strange build errors..
Here is my code:
#include <QtCore/QCoreApplication>
#include "downloadpage.h"
int main(int argc, char *argv[])
{
DownloadPage downloadPage;
downloadPage.startDownload();
return a.exec();
}
#include <QtCore/QCoreApplication>
#include "downloadpage.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DownloadPage downloadPage;
downloadPage.startDownload();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
#ifndef DOWNLOADPAGE_H
#define DOWNLOADPAGE_H
#include <Qt/QtNetwork>
#include <QDebug>
{
Q_OBJECT
public:
DownloadPage();
void startDownload();
private slots:
void downloadComplete(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
};
#endif // DOWNLOADPAGE_H
#ifndef DOWNLOADPAGE_H
#define DOWNLOADPAGE_H
#include <Qt/QtNetwork>
#include <QDebug>
class DownloadPage:QObject
{
Q_OBJECT
public:
DownloadPage();
void startDownload();
private slots:
void downloadComplete(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
};
#endif // DOWNLOADPAGE_H
To copy to clipboard, switch view to plain text mode
#include "downloadpage.h"
DownloadPage::DownloadPage()
{
qDebug()<<"Download Page constructor called";
manager = new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(downloadComplete(QNetworkReply*)));
}
void DownloadPage::startDownload(){
qDebug()<<"Downloading Page...";
manager
->get
(QNetworkRequest
(QUrl("http://www.google.ch")));
qDebug()<<"Page call end but not finished yet";
}
void DownloadPage::downloadComplete(QNetworkReply *reply){
qDebug()<<"Page call finished";
}
#include "downloadpage.h"
DownloadPage::DownloadPage()
{
qDebug()<<"Download Page constructor called";
manager = new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(downloadComplete(QNetworkReply*)));
}
void DownloadPage::startDownload(){
qDebug()<<"Downloading Page...";
manager->get(QNetworkRequest(QUrl("http://www.google.ch")));
qDebug()<<"Page call end but not finished yet";
}
void DownloadPage::downloadComplete(QNetworkReply *reply){
qDebug()<<"Page call finished";
}
To copy to clipboard, switch view to plain text mode
and my build errors are:
debug/downloadpage.o: In function `DownloadPage':
D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:6: undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject'
D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:6: undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject'
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'
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'
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'
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'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug\ComeOn.exe] Error 1
mingw32-make.exe: *** [debug] Error 2
21:36:03: The process "D:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project ComeOn (target: Desktop)
When executing build step 'Make'
debug/downloadpage.o: In function `DownloadPage':
D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:6: undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject'
D:\Desktop\ComeOn-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/../ComeOn/downloadpage.cpp:6: undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject'
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'
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'
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'
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'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug\ComeOn.exe] Error 1
mingw32-make.exe: *** [debug] Error 2
21:36:03: The process "D:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project ComeOn (target: Desktop)
When executing build step 'Make'
To copy to clipboard, switch view to plain text mode
Does anybody have an idea?
Thanks!
Bookmarks