简体   繁体   中英

Qt with codeblocks - undefined reference to vtable

I've created project in qt (GUI and skeleton for logic), and then I've created QT project in codeblocks in order to do coding part in this IDE.
Unfortunately I'm getting errors in style: undefined reference to vtable for Calc_Button, etc.
This code compiles fine with Qt but it doesn't want to compile with codeblocks. The same compiler is used.
I can provide code, but it is really quite a lot of it - even just the stubs.
That's how Calc_Button class looks like:

#ifndef CALC_BUTTON_H
#define CALC_BUTTON_H

#include <QPushButton>

class Calc_Button : public QPushButton
{
    Q_OBJECT
private:
protected:

public:
    explicit Calc_Button(QWidget *parent = 0);

signals:
    void clicked(QString);

public slots:
    void click()
    {
        emit clicked(QString(this->text()));
    }

};

#endif // CALC_BUTTON_H

and this is cpp:

#include "calc_button.h"

Calc_Button::Calc_Button(QWidget *parent) :    QPushButton(parent)
{

}

This error message is usually misleading but it the actual reason is (usually) that You did not define one of your virtual functions.

Here is a sample demo :

class MyClass
{
    public:
    virtual void doSomething() { }
    virtual void doSomethingMore();
};

int main()
{
    MyClass obj;
    obj.doSomething();
    obj.doSomethingMore();
    return 0;
}

compilation info:

/home/4VqWl0/ccMjLi2V.o: In function main':
prog.cpp:(.text+0x19): undefined reference to
main':
prog.cpp:(.text+0x19): undefined reference to
main':
prog.cpp:(.text+0x19): undefined reference to
vtable for MyClass .
prog.cpp:(.text+0x1e): undefined reference to
.
prog.cpp:(.text+0x1e): undefined reference to
.
prog.cpp:(.text+0x1e): undefined reference to
MyClass::doSomethingMore()'

collect2: ld returned 1 exit status

Good Read:

What does it mean that the "virtual table" is an unresolved external?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM