0

I am trying to implement a basic http connection http://developer.nokia.com/community/wiki/Creating_an_HTTP_network_request_in_Qt into Qt but I have difficultly implementing the slot. I am a Qt novice.

C:\Qt5\Tools\QtCreator\bin\miniHTTP\main.cpp:10: error: request for member 'Test' in 'mTest', which is of non-class type 'coreEng()' mTest.Test();

//main.cpp

#include <QCoreApplication>
#include <coreeng.h>


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    coreEng mTest;
    mTest.Test();
    return a.exec();
}

//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

//coreeng.cpp

#include "coreeng.h"
#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QImageReader>

coreEng::coreEng(QNetworkReply* parent) :
    QObject(parent)

{
}

void coreEng::Test();

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;

}
brad
  • 870
  • 2
  • 13
  • 38
  • http://en.wikipedia.org/wiki/Most_vexing_parse change `coreEng mTest();` to `coreEng mTest;` – drescherjm Jun 11 '14 at 18:25
  • @drescherjm Thank you. That appears to of got me a little farther, but I am still having issues initializing the object -> coreeng.cpp:8: error: prototype for 'coreEng::coreEng(QNetworkReply*)' does not match any in class 'coreEng' – brad Jun 11 '14 at 18:31

3 Answers3

1

You have declared void Test(); as a member function in the header file and have not implemented it in the cpp file. You should implement it :

void coreEng::Test()
{
    ...
}
Nejat
  • 31,784
  • 12
  • 106
  • 138
1

In addition to other problems already described, your implementation of finished slot doesn't have the same signature of as the function definition. In your .h file you have:

void finishedSlot();

Whereas your .cpp has:

void finishedSlot(QNetworkReply *reply) {
    /*code here*/
}

So to summarise:

  1. Add an implementation of your test function:

    void coreEng::Test() { /code here/ }

  2. Fix the signature of your constructor so that .cpp and .h files agree:

    coreEng::coreEng(QObject* parent) : QObject(parent) { /code here/ }

  3. Fix the signature of your finishedSlot so that .cpp and .h files agree:

    void finishedSlot(QNetworkReply *reply);

These changes will at least get you to the stage that you're compiling successfully.

dannyp
  • 29
  • 2
0

One problem is you are running into the most vexing parse: http://en.wikipedia.org/wiki/Most_vexing_parse

Most vexing parse

Change

coreEng mTest();

to

coreEng mTest;

A second problem is your constructor in coreeng.cpp has the wrong signature

Change:

coreEng::coreEng(QNetworkReply*) :
    QObject(parent)

to

   coreEng::coreEng(QObject* parent) :
        QObject(parent)
Community
  • 1
  • 1
drescherjm
  • 10,365
  • 5
  • 44
  • 64