我试过运行qmake来重建Makefile,但是创建者仍然给我同样的错误coreeng.h:7:错误:对`vtable for coreEng'的未定义引用:我无法正确访问该类。

//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);
        private slots:

        public slots:
            void connect();
            void url();
            void finishedSlot(QNetworkReply* reply);


        private:
            QNetworkAccessManager* nam;

};

#endif // COREENG_H


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

}


//main.cpp

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


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

    coreEng mConnect;
    mConnect.connect();
    return a.exec();
}

最佳答案

这似乎是GUI错误。
重新启动了创作者,这种特殊情况消失了。

10-08 09:48