I trying to implement this code http://developer.nokia.com/community/wiki/Creating_an_HTTP_network_request_in_Qt and when I try and access the class coreEng::url() I get the following error ->
main.cpp:10: error: undefined reference to `coreEng::url()'
I have tried qDebug but get no output.
//coreeng.cpp
#include "coreeng.h"
#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QImageReader>
coreEng::coreEng(QObject* parent) :
QObject(parent)
{
}
void coreEng::connect(){
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),
this, SLOT(finishedSlot(QNetworkReply*)));
}
void coreEng::url(){
QUrl url("http://www.forum.nokia.wiki");
QNetworkReply* reply = nam->get(QNetworkRequest(url));
}
void coreEng::finishedSlot(QNetworkReply* reply){
QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
QVariant redirectionTargetUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (reply->error() == QNetworkReply::NoError)
{
QImageReader imageReader(reply);
QImage pic = imageReader.read();
QByteArray bytes = reply->readAll(); // bytes
QString string(bytes); // string
}
else
{
}
delete reply;
}
//coreeng.h
#ifndef COREENG_H
#define COREENG_H
#include <QDebug>
#include <QObject>
#include <QNetworkAccessManager>
class coreEng : public QObject
{
Q_OBJECT
public:
explicit coreEng(QObject *parent = 0);
void Test();
private slots:
public slots:
void connect();
void url();
void finishedSlot();
private:
QNetworkAccessManager* nam;
};
#endif // COREENG_H
//main.cpp
#include <QCoreApplication>
#include <coreeng.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
coreEng mTest;
mTest.Test();
return a.exec();
}