对' vtable '的未定义引用(最小示例)
undefined reference to `vtable (with minimal example)
这可能是下一个重复,但是我没有在这段代码中找到错误:
#include <qwt_plot.h>
class QLinePlot : public QwtPlot
{
Q_OBJECT
public:
QLinePlot(QWidget* parent = 0, Qt::WindowFlags flags = 0): QwtPlot(parent)
{
}
~QLinePlot()
{
}
};
int main( int argc, char **argv )
{
QLinePlot * plot = new QLinePlot();
}
我删除了构建文件夹,并再次运行qmake,但没有变化。错误信息是
test.cpp:7: undefined reference to `vtable for QLinePlot'
您的文件末尾缺少一个#include "test.moc"
:
// test.cpp
#include <qwt_plot.h>
class QLinePlot : public QwtPlot
{
Q_OBJECT
public:
using QwtPlot::QwtPlot;
};
int main( int argc, char **argv )
{
QLinePlot plot;
}
#include "test.moc"
添加include行后,必须在项目上重新运行qmake。
你的例子不是最小的,但是。要重现这个问题,只需:
#include <QObject>
class Foo : public QObject {
Q_OBJECT
~Foo() {}
}
int main() { Foo foo; }
你应该有你的QLinePlot
类在头文件test.h
。这样更简洁,而且您不需要在test.cpp
中包含test.moc
。例如
test.cpp
#include "test.h"
int main( int argc, char **argv )
{
QLinePlot plot;
}
test.h
#include <qwt_plot.h>
class QLinePlot : public QwtPlot
{
Q_OBJECT
// stuff
};
相关文章:
- 纯虚拟类和错误未定义对 'vtable 的引用
- 对植物的 vtable 的未定义引用?
- 未定义的符号缺少 vtable
- 使用多个命名空间对 vtable 的未定义引用
- 对"车辆的 vtable"的未定义引用 - 面向对象的编程练习
- Qt Quick + CMake + 自定义 QObject 导致对"vtable"的未定义引用
- C++ 未定义对 vtable 异常的引用
- 看起来如此主要的错误.cpp:(.text.startup+0xd6):未定义对"vtable for Counter"的引用?
- 用嵌套类对VTable的未定义引用
- 未定义对 vtable 错误的引用
- 对'vtable for class'的未定义引用
- 奇怪的未定义引用了`vtable
- 构造函数中对"vtable"的未定义引用
- C++ 继承问题:未定义对"vtable"的引用
- 构造函数中对 vtable 的未定义引用
- 在 qt 控制台应用程序中未定义对 'vtable for myObj' 的引用 - 信号和插槽
- 关于vtable符号可能未定义,因为类缺少其键函数
- 访问VTable直接发出未定义的错误
- 为KRunner定义插件时未定义vtable
- 链接错误未定义vtable和typeinfo