Qt Designer 带有自定义小部件插件的未定义符号
我在 Fedora 14 下使用 Qt 4.7.2。
我有一个自定义小部件的工作库,我正在尝试将其集成到 Qt Designer 中。 有一个简单的小部件基类,然后是一些从它继承的更复杂的小部件。 简单的小部件集成得很好,但我对更复杂的小部件有问题。
问题在于,更复杂的结构需要在创建时传递给它们特殊的结构。所以我在插件中创建复杂小部件的代码是:
QWidget *myPlugin::createWidget(QWidget *parent)
{
my_struct *xyz = new my_struct;
return new myWidget("MyWidget",xyz, parent);
}
my_struct 只是一个带有整数、双精度和数组的简单 C 风格结构。
然后,当我使用此插件启动 Qt Designer 时,我得到:
/usr/lib64/qt4/bin/designer: symbol lookup error: /usr/lib64/qt4/plugins/designer/libMyPlugin.so: undefined symbol: _ZN8MyWidgetC1E7QStringP17my_structP7QWidget
我正在构建该插件的发布版本,而不是调试版本。
我还尝试在插件中将 xyz 定义为静态类变量,然后将其地址传递给构造函数,但我仍然遇到相同的错误。
我还尝试将 xyx 作为未使用的静态类变量添加到我的简单小部件中,并且不会给出错误,因此错误似乎来自对 myWidget 构造函数的调用。
谁能帮我解决这个问题吗?
谢谢阿恩,
你是对的。
我将我的库明确添加到插件的 .pro 文件中,然后它就起作用了。
让我困惑的是,如果没有库,我如何才能构建没有错误的插件? 为什么我的简单小部件在没有库的情况下也能工作?
I am using Qt 4.7.2 under Fedora 14.
I have a working library of custom widgets which I am trying to integrate into Qt Designer.
There is a simple widget base class, then some more complex widgets inheriting from it.
The simple widget integrates fine, but I have a problem with the more complex ones.
The problem comes from the fact that that the more complex ones require a special structure to be passed to them on creation. So my code for creating a complex widget in the plugin is:
QWidget *myPlugin::createWidget(QWidget *parent)
{
my_struct *xyz = new my_struct;
return new myWidget("MyWidget",xyz, parent);
}
my_struct is just a simple C style struct with ints, doubles and arrays.
Then when I start Qt Designer with this plugin I get:
/usr/lib64/qt4/bin/designer: symbol lookup error: /usr/lib64/qt4/plugins/designer/libMyPlugin.so: undefined symbol: _ZN8MyWidgetC1E7QStringP17my_structP7QWidget
I am building a release version of the plugin, not a debug version.
I also tried defining xyz as a static class variable in the plugin and just passing its address to the constructor, but I still get the same error.
I also tried adding xyx as an unused static class variable to my simple widget and that does not give the error, so the error seems to be coming from the call to the myWidget constuctor.
Can anyone help me resolve this?
Thanks Arne,
You were right.
I added my library explicitly to the plugin's .pro file and then it worked.
What puzzles me is how could I build the plugin with no errors without the library?
And why did my simple widget work without the library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误消息看起来好像链接器没有找到构造函数
myWidget(QString, my_struct*, QWidget*)
的定义。您是否已将相关源文件添加到您的发布版本中?你真的有这个构造函数的定义吗?您也可能必须交换目标文件链接顺序。我过去在大型项目中见过这种情况,所以我不会太惊讶。包含定义的目标文件需要在使用该定义的目标文件之前声明。The error message looks as if the linker did not find a definition for the constructor
myWidget(QString, my_struct*, QWidget*)
. Have you added the relevant source file to your release build? Do you actually have a definition for this constructor? It is also possible that you have to exchange the object file linking order. I have seen this with larger projects in the past, so I wouldn't be too surprised. The object file containing the definition needs to be stated before the one using the definition.