Qt带有代码块 - 未定义对vtable的引用 [英] Qt with codeblocks - undefined reference to vtable

查看:1184
本文介绍了Qt带有代码块 - 未定义对vtable的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在qt(逻辑的GUI和骨架)中创建了项目,然后我在代码块中创建了QT项目,以便在这个IDE中编码部分。

不幸的是,我得到了样式中的错误:未定义对Calc_Button的vtable的引用等。

此代码使用Qt编译良好,但它不想使用代码块编译。使用相同的编译器。

我可以提供代码,但它是非常多的 - 即使只是存根。

这就是Calc_Button类看起来像:

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

这是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;
}

编译信息:

/home/4VqWl0/ccMjLi2V.o:在函数 main'中:

prog.cpp :(。text + 0x19):undefined vtable for MyClass

prog.cpp :(。text + 0x1e):未定义的引用
MyClass :: doSomethingMore )'

collect2:ld退回1退出状态

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

良好阅读:

这是什么意味着虚拟表是未解决的外部?

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

这篇关于Qt带有代码块 - 未定义对vtable的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆