Qt vtable错误 [英] Qt vtable error

查看:259
本文介绍了Qt vtable错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将通过旧的Trolltech Qt教程,因为我发现他们比新的更有帮助,并且一个未定义的参考vtable 错误打我,当我得到一个类widget实现自己的信号。

I'm going through the old Trolltech Qt tutorials as I find them more helpful than the newer ones and an undefined reference to vtable error hits me when I got to a class widget implementing its own signals.

http:// doc。 trolltech.com/4.0/tutorial-t7.html

我不是将代码分开,而是将它们全部复制到同一个 .cpp

Instead of keeping the code separate, I just copied them all in the same .cpp for convenience.

我窥探了一下,发现vtable错误是由未定义的虚函数引起的。但是,除了代码分隔之外,我没有省略教程代码中的任何内容。从 lcdrange.h 省略 Q_OBJECT 宏以及插槽和信号似乎使项目编译。我认为它是 void valueChanged(int newValue); 在 lcdrange.h 这是引起轰动,但教程没有提供定义。我敢肯定,他们不会post代码不工作,所以我一定做错了。我使用C :: B(MinGW)如果这意味着任何东西。我也是C ++的新手。

I snooped around and found that a vtable error is caused by an undefined virtual function. However, I didn't omit anything from the tutorial code except the code separation. Omitting the Q_OBJECT macro from lcdrange.h as well as the slots and signals seem to make the project compile. I figure it's void valueChanged(int newValue); at lcdrange.h that is causing the fuss but the tutorial did not provide a definition. I'm sure they won't post code that isn't working so I must be doing something wrong. I'm using C::B(MinGW) if that means anything. I'm also new to C++.

推荐答案

MOC必须为lcdrange.h生成代码,生成的代码必须编译和链接。
qmake为HEADERS变量中列出的所有头文件确保这一点。
确保lcdrange.h列在.pro文件的HEADERS部分,然后重新运行qmake。

MOC must generate code for lcdrange.h and the generated code must be compiled and linked. qmake ensures this for all header files listed in the HEADERS variable. Make sure lcdrange.h is listed in the HEADERS section of your .pro file, and rerun qmake.

这篇关于Qt vtable错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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