PDA

View Full Version : QPluginLoader doesn't accept plugin name



Gourmet
8th June 2011, 11:23
I'm weird. Just made plugin as described in books. All looks fine. In main application I try load it but got unexpected problem:


MainWindow::MainWindow(QApplication* a, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QDir dir( QApplication::applicationDirPath() );
QString abspath = dir.absoluteFilePath( "EmptyPlugin.dll" ); // name correct in abspath
QPluginLoader PluginLoader( abspath );
abspath = PluginLoader.fileName(); // name empty!!! ?????????
QObject * plugin = qobject_cast<QObject*>( PluginLoader.instance() );
QString errstr;
if( ! plugin )
errstr = PluginLoader.errorString(); // contains "Unknown error"
}


1st time abspath is correct, but 2nd time it... is empty :confused:

tried this:


MainWindow::MainWindow(QApplication* a, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QDir dir( QApplication::applicationDirPath() );
QString abspath = dir.absoluteFilePath( "EmptyPlugin.dll" ); // name correct
QPluginLoader PluginLoader( "" );
PluginLoader.setFileName( abspath );
abspath = PluginLoader.fileName(); // name empty!!! ?????????
QObject * plugin = qobject_cast<QObject*>( PluginLoader.instance() );
QString errstr;
if( ! plugin )
errstr = PluginLoader.errorString(); // contains "Unknown error"
}


effect is the same, no plugin file name assigned

why this can happen? PLEASE HELP!

joyer83
8th June 2011, 13:47
Err, you have defined the abspath two times in same scope.
Have you actually compiled your code successfully?

Gourmet
8th June 2011, 14:59
sorry, this was my copy-paste error just in message, I fixed it

the code exactly is little different (like now in first message) and compiles and starts well

I even did the following:


QPluginLoader PluginLoader("");
PluginLoader.setFileName( "I:/Qt/2010.05s/projects/sources/SCPS-M-build-desktop/debug/EmptyPlugin.dll" ); // file definitely exists and pathname is right
QString errstr = PluginLoader.errorString(); // "Unknown error"
errstr = PluginLoader.fileName(); // empty


and following:


QPluginLoader PluginLoader("");
PluginLoader.setFileName( "I:\\Qt\\2010.05s\\projects\\sources\\SCPS-M-build-desktop\\debug\\EmptyPlugin.dll" ); // file definitely exists and pathname is right
QString errstr = PluginLoader.errorString(); // "Unknown error"
errstr = PluginLoader.fileName(); // empty


both with same result

looks like a bug in Qt 4.7 for Windows - QPluginLoader does not accept absolute plugin path

QLibrary itself works well, I tested - but I need plugins because of C++ classes

Added after 1:

ANYBODY CONFIRM OR DECLINE THIS BEHAVIOUR!

I want write bug report but need more statistic.

Gourmet
8th June 2011, 16:01
SOLVED. Application was made static because of wrong Qt selected in it's project. Dynamically linked plugins don't work with static applications.