简体   繁体   English

Qt Designer带有自定义小部件插件的未定义符号

[英]Qt Designer undefined symbol with Custom Widget plugin

I am using Qt 4.7.2 under Fedora 14. 我正在Fedora 14下使用Qt 4.7.2。

I have a working library of custom widgets which I am trying to integrate into Qt Designer. 我有一个自定义小部件的工作库,正在尝试将其集成到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. my_struct只是一个简单的C样式结构,具有整数,双精度数和数组。

Then when I start Qt Designer with this plugin I get: 然后,当我使用此插件启动Qt Designer时,我得到:

/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. 我还尝试将xyz定义为插件中的静态类变量,然后将其地址传递给构造函数,但是仍然遇到相同的错误。

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. 我还尝试将xyx作为未使用的静态类变量添加到我的简单小部件中,但是这并没有给出错误,因此错误似乎出自对myWidget构造函数的调用。

Can anyone help me resolve this? 谁能帮我解决这个问题?


Thanks Arne, 感谢Arne,

You were right. 你是对的。

I added my library explicitly to the plugin's .pro file and then it worked. 我将库明确添加到插件的.pro文件中,然后它起作用了。

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? 为什么我的简单窗口小部件在没有库的情况下也可以工作?

The error message looks as if the linker did not find a definition for the constructor myWidget(QString, my_struct*, QWidget*) . 该错误消息看起来好像链接程序没有找到构造函数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. 包含定义的目标文件需要在使用该定义的文件之前声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM