-5

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();
}
brad
  • 870
  • 2
  • 13
  • 38
  • 1
    Where is your `Test` method defined ? It is only declared. – Halim Qarroum Jun 12 '14 at 09:30
  • "Class access" is not a very good term to describe this situation. It's a totally arbitrary pair of words with no connection to the problem in hand. You have an undefined reference error. Say so in the title. – n. m. could be an AI Jun 12 '14 at 09:36
  • possible duplicate of [slot error using QNetworkAccessManager](http://stackoverflow.com/questions/24168779/slot-error-using-qnetworkaccessmanager) – Nejat Jun 12 '14 at 09:46

2 Answers2

0

You have defined the Test() function in the header for the class coreEng, but failed to implement the class.

At the very least, you can put braces at the end of the definition in the header file: -

void Test() {}

Or implement the function in the cpp

void coreEng::Test() 
{
    // perform test
}
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • Thank for your response. I get errors with both attempts. void coreEng::Test(){} give me an extra qualifier coreEng error. And void Test(){} gives error -> undefined reference to coreEng Test() -> http://i.imgur.com/bexnbT5.png – brad Jun 12 '14 at 14:45
  • Yes, that was the answer. – brad Jun 22 '14 at 21:42
0

Did you see the error, undefined reference to 'vtable for coreEng'?

I would say first rectify that error. Try to follow this link:

https://qt-project.org/forums/viewthread/6084

Or I would say search more how to solve this error.

After removing this error, tell whether the error you have asked in question still remains.