简体   繁体   中英

Qt Designer undefined symbol with Custom Widget plugin

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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