PDA

View Full Version : Qt Plugins Error



nathanpackard
18th August 2007, 00:07
Hello,

I was wondering if anyone could help me out with a strange error I get working with plugins. I'm building a plugin based application and I've successfully loaded plugins and used them in my application (similar to the plug and paint example). I'm trying to add another plugin which links to a 3rd party library (GDCM - GNU Dicom Library). I've modified the .pro file to link to these libraries (using LIBS = ...) and the plugin compiles fine and loads fine in my application. The code in my main application loads plugins like this:

void MainWindow::loadPlugins(){
//Find the plugins Directory
//QDir pluginsDir = QDir(qApp->applicationDirPath(),"",QDir::Reversed);
QDir pluginsDir = QDir(qApp->applicationDirPath(),"");

#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS") {
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
}
#endif
pluginsDir.cd("plugins");

foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader* pLoader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName ));
printf(fileName.toAscii().data());
if (pLoader){
QObject *plugin = pLoader->instance();
printf("1");
if (plugin) {
printf("2\n");

So as it loads the plugins, it prints the name of the file, then '1', then '2'

However, when I add code that uses the 3rd party library to my plugin, The plugin still compiles with no complaints, but it won't load as a plugin in my application. It loads the other plugins fine, but it only prints '1' (not '2') when loading the modified plugin. So, pLoader->instance() now returns 0 after adding in the code from the 3rd party library.

Does anyone have any idea as to what might be going on??

Thanks,

Nathan

PS - One possible explaination could be as described here:
"When you build the plugin, the linker won't complaint about missing symbols as it is a dynamic library pending to be linked on runtime. Later, when the plugin host (either designer or a QUiLoader based app) tries to load it and fails, it does not complain at all neither. Just that the plugin won't be available but no error message is displayed."
-- http://www.iua.upf.edu/~dgarcia/Codders/qtpluginnotloading.html

But I tried compiling "cl plugintest.cpp /link qvol_dicomdoc.lib" and got no error

jpn
18th August 2007, 00:19
Hi

Yes, the application of yours must link to that 3rd party library. By the way, I suppose you would get the reason (a linkage error) if you turned the plugin temporarily as static.