QT undefined reference to VTable

Hi guys,

I am getting aUser\Documents\doHttpTwo\main.cpp:15: error: undefined reference to `vtable for Downloader' error when I try to build my project in QT,

I added a virtual destructor and it still didn't fix the problem,

any idea why I am getting this error?

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <QCoreApplication>
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QDateTime>
#include <QFile>
#include <QDebug>

class Downloader : public QObject
{
    Q_OBJECT
public:
    explicit Downloader(QObject *parent = 0){

    }
    virtual ~Downloader(){

        delete manager;
    }

    void doDownload(){
        manager = new QNetworkAccessManager(this);

        connect(manager, SIGNAL(finished(QNetworkReply*)),
                    this, SLOT(replyFinished(QNetworkReply*)));

        manager->get(QNetworkRequest(QUrl("http://bogotobogo.com")));

    }

signals:

public slots:
    void replyFinished (QNetworkReply *reply){
        if(reply->error())
           {
               qDebug() << "ERROR!";
               qDebug() << reply->errorString();
           }

    }

private:
   QNetworkAccessManager *manager;

};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Downloader d;
    d.doDownload();

    return a.exec();
}
Last edited on
Is that the only error/warning message? Is that message the exact message your development environment is actually reporting?
yes seems to be the only error,

I moved the code into a header and a source file instead and all works fine,but I still want to get to the bottom of why it wouldn't work :/
It is a known issue with GCC and with Qt.
https://stackoverflow.com/questions/1552069/undefined-reference-to-vtable-trying-to-compile-a-qt-project

You must make sure that MOC generates functions for every cpp, since if a virtual method is not defined in a subclass you will get this error.
http://gcc.gnu.org/faq.html#vtables

Good luck!
Topic archived. No new replies allowed.