Qt、VS2005、Qwt - 不能在从 Qwt 小部件派生的类中使用 Q_OBJECT [英] Qt, VS2005, Qwt - Can't use Q_OBJECT in class derived from Qwt widgets

查看:35
本文介绍了Qt、VS2005、Qwt - 不能在从 Qwt 小部件派生的类中使用 Q_OBJECT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经为 VS2005 编译了 QT 4.6 和 QWT 5.2.0.

We've compiled QT 4.6 and QWT 5.2.0 for VS2005.

我们试图从 QwtDial 派生一个类,并且派生类有插槽.所以,我们需要添加 Q_OBJECT 宏.但是,当我们这样做时,链接器会阻止此错误:

We're trying to derive a class from QwtDial, and the derived class has slots. So, we need to add the Q_OBJECT macro. However, when we do that, the linker chokes out this error:

错误 LNK2001: 未解析的外部符号 "public: static struct QMetaObject const QwtDial::staticMetaObject" (?staticMetaObject@QwtDial@@2UQMetaObject@@B)

error LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtDial::staticMetaObject" (?staticMetaObject@QwtDial@@2UQMetaObject@@B)

我已经查看了带有depends 的Qwt.dll,它具有该功能.使用十六进制编辑器查看 .lib 文件显示它与该名称错误的字符串完全匹配.

I've looked at the Qwt.dll with depends, and it has that function. Looking at the .lib file with a hex editor shows it has an exact match for that name-mangled string.

我们在路径中有 Qwt 库.实际上,如果我重命名 lib,则会出现找不到 lib 文件的错误.所以,我们知道它正在寻找正确的库.

We have the Qwt lib in the path. Actually, if I rename the lib, then it gives an error that it can't find the lib file. So, we know it's looking at the right lib.

如果我们跳过 Q_OBJECT,那么所有内容都可以使用多个 QWT 小部件正确链接和绘制,包括我们的非 Q_OBJECT Qwt 派生类.

If we skip the Q_OBJECT, then everything links and draws correctly using several QWT widgets, including our non-Q_OBJECT Qwt derived classes.

有谁知道是什么导致了这个非常烦人的链接器问题?

Does anyone know what can cause this really annoying linker issue?

更新:

我已经验证我添加 Q_OBJECT 的类肯定会得到一个为其生成的 MOC 文件.链接器错误实际上来自这个生成的 MOC 文件:

I've verified that the class I add the Q_OBJECT to definitely is getting a MOC file generated for it. The linker error is actually coming from this generated MOC file:

moc_GaugeWidget1.obj : error LNK2001: unresolved external symbol "public: static
    struct QMetaObject const QwtDial::staticMetaObject" 
    (?staticMetaObject@QwtDial@@2UQMetaObject@@B)

所以,它看起来非常奇怪和非典型.符号肯定在库中.

So, it's looking like something quite stange and atypical. The symbol is definitely in the lib.

推荐答案

我遇到了同样的问题.好吧,我正在使用 Qt4.4 和 VC2003 更新一个旧项目,并且我正在使用 QwtPlot 而不是 QwtDial.错误是:

I am having the same problem. Well, I'm updating an old project using Qt4.4 and VC2003, and I'm using QwtPlot instead of QwtDial. The error is:

LNK2001: 未解析的外部符号 "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B)

LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B)

就是这样.没有其他的.我发现论坛参考资料指出调试/发布混淆问题,可能与删除 Qt Designer 插件有关.

Just that. Nothing else. I've found forum references pointing to issues with debug/release mixups and possibly something to do with removing the Qt Designer plugin.

这似乎对我有用:在 project.pro 文件的顶部添加以下行:DEFINES += QWT_DLL".

This seems to be working for me: Add the line: "DEFINES += QWT_DLL" to the top of the project.pro file.

qmake project.pro

qmake project.pro

nmake 发布

这篇关于Qt、VS2005、Qwt - 不能在从 Qwt 小部件派生的类中使用 Q_OBJECT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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