QObject 创建 moc 文件,但仍然出现 vtable 错误
在将 PrimitivePartsWrapper 设为 QObject 的子类(包括 Q_OBJECT 宏)后,我似乎无法摆脱此错误。
undefined reference to `vtable for PrimitivePartsWrapper` (in register.o)
我已经运行了 qmake,并且 moc_primitive.cpp 包含在 makefile 中。这似乎只发生在 Qt Creator 中。如果我在命令行上运行 make,程序会编译,但我的嵌入式 python 会出现错误,无法找到 PrimitiveParts 类,这可能是不相关的。 QtCreator中的错误与register.o而不是primitive.o有关吗?或者 moc_primitive.o?
原语.h:
#ifndef PRIMITIVE_H
#define PRIMITIVE_H
#include "util.h"
class PrimitiveParts {
public:
QVector<Point3> points;
QVector<QList<int> > faces;
};
class PrimitivePartsWrapper : public QObject
{
Q_OBJECT
public slots:
PrimitiveParts* new_PrimitiveParts();
};
namespace primitive {
PrimitiveParts cubePrimitive(float width, float height, float depth);
};
#endif // PRIMITIVE_H
原语.cpp:
#include "primitive.h"
PrimitiveParts* PrimitivePartsWrapper::new_PrimitiveParts()
{
return new PrimitiveParts();
}
namespace primitive {
PrimitiveParts cubePrimitive(float width, float height, float depth)
{
float hx = width / 2;
float hy = height / 2;
float hz = depth / 2;
// create the vertices
Point3 p0(hx,hy,hz);
Point3 p1(hx,hy,-hz);
Point3 p2(-hx,hy,-hz);
Point3 p3(-hx,hy,hz);
Point3 p4(hx,-hy,hz);
Point3 p5(hx,-hy,-hz);
Point3 p6(-hx,-hy,-hz);
Point3 p7(-hx,-hy,hz);
QList<int> f0 = QList<int>() << 0 << 1 << 2 << 3;
QList<int> f1 = QList<int>() << 4 << 5 << 1 << 0;
QList<int> f2 = QList<int>() << 6 << 2 << 1 << 5;
QList<int> f3 = QList<int>() << 7 << 3 << 2 << 6;
QList<int> f4 = QList<int>() << 7 << 4 << 0 << 3;
QList<int> f5 = QList<int>() << 4 << 7 << 6 << 5;
struct PrimitiveParts parts;
parts.points = QVector<Point3>() << p0 << p1 << p2 << p3 << p4 << p5 << p6 << p7;
parts.faces = QVector<QList<int> >() << f0 << f1 << f2 << f3 << f4 << f5;
return parts;
}
};
I can't seem to shake this error after making PrimitivePartsWrapper a subclass of QObject (including the Q_OBJECT macro).
undefined reference to `vtable for PrimitivePartsWrapper` (in register.o)
I've ran qmake, and the moc_primitive.cpp is included in the makefile. It only seems to happen in Qt creator. If I run make on the command-line, the program compiles but I get an error in my embedded python not being able to find that PrimitiveParts class, which may be unrelated. Does the error in QtCreator have anything to do with register.o instead of primitive.o? Or moc_primitive.o?
primitive.h:
#ifndef PRIMITIVE_H
#define PRIMITIVE_H
#include "util.h"
class PrimitiveParts {
public:
QVector<Point3> points;
QVector<QList<int> > faces;
};
class PrimitivePartsWrapper : public QObject
{
Q_OBJECT
public slots:
PrimitiveParts* new_PrimitiveParts();
};
namespace primitive {
PrimitiveParts cubePrimitive(float width, float height, float depth);
};
#endif // PRIMITIVE_H
primitive.cpp:
#include "primitive.h"
PrimitiveParts* PrimitivePartsWrapper::new_PrimitiveParts()
{
return new PrimitiveParts();
}
namespace primitive {
PrimitiveParts cubePrimitive(float width, float height, float depth)
{
float hx = width / 2;
float hy = height / 2;
float hz = depth / 2;
// create the vertices
Point3 p0(hx,hy,hz);
Point3 p1(hx,hy,-hz);
Point3 p2(-hx,hy,-hz);
Point3 p3(-hx,hy,hz);
Point3 p4(hx,-hy,hz);
Point3 p5(hx,-hy,-hz);
Point3 p6(-hx,-hy,-hz);
Point3 p7(-hx,-hy,hz);
QList<int> f0 = QList<int>() << 0 << 1 << 2 << 3;
QList<int> f1 = QList<int>() << 4 << 5 << 1 << 0;
QList<int> f2 = QList<int>() << 6 << 2 << 1 << 5;
QList<int> f3 = QList<int>() << 7 << 3 << 2 << 6;
QList<int> f4 = QList<int>() << 7 << 4 << 0 << 3;
QList<int> f5 = QList<int>() << 4 << 7 << 6 << 5;
struct PrimitiveParts parts;
parts.points = QVector<Point3>() << p0 << p1 << p2 << p3 << p4 << p5 << p6 << p7;
parts.faces = QVector<QList<int> >() << f0 << f1 << f2 << f3 << f4 << f5;
return parts;
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有提供所有代码,但无论如何尝试清理您的项目,重新运行 qmake 并重建所有代码。
You didn't provide all the code, but anyway try to clean your project, re-run qmake and rebuild all.