QT plugins: a plugin that is a GUI
I don't understand how to create an empy application that only loads a plugin that is a GUI itself.
I cannot make it work ... :confused:
Actually I have a main.cpp that creates and executes a QApplication
Code:
int main(int argc, char *argv[])
{
MainApp app(argc, argv);
return app.exec();
}
Code:
{
Q_OBJECT
public:
MainApp(int &argc, char **argv);
~MainApp();
private:
void loadPlugins();
}
when MainApp is created it calls loadPlugins:
Code:
MainApp::MainApp(int &argc, char **argv) :
{
loadPlugins();
}
QPluginLoader loader(..) fails as I get:
Quote:
ERROR !!! loader.isLoaded(): <0> - loader.errorString(): <Unknown error>
Does anybody know something about it ?
Thanks.
Re: QT plugins: a plugin that is a GUI
What is the contents of your loadPlugins() method?
Re: QT plugins: a plugin that is a GUI
No it's ok now, I've forgotten to write that the problem was this one:
http://www.qtcentre.org/forum/f-qt-p...uis-25178.html
in few words the gui I've created could not start properly for some stupid problem (the more the problem is stupid and near you, the more far you search for a solution :D) so the plugin was not loaded.
But the strange thing is that I had to remove the check (if loader.isLoaded()) as it returned false also after having correted the error.
anyway, my loadPlugins is the following:
Code:
void MainApp::loadPlugins()
{
pluginsDir
= QDir(qApp
->applicationDirPath
());
pluginsDir.cd("plugins");
foreach
(QString fileName, pluginsDir.
entryList(QDir::Files)) {
//if ( ! loader.isLoaded() )
//{
// puts("ERROR: plugin not loaded !");
// return;
//}
QObject *plugin
= loader.
instance();
if (plugin)
{
BaseInterface * b = qobject_cast<BaseInterface*>(plugin);
if (b)
{
puts("Plugin loaded - setting config file ...");
b->SetConfigFileName("objects.xml");
puts("Starting plugin ...");
b->Start();
}
else
{
puts("ERROR: Could not convert Plugin !!! ");
}
pluginFileNames += fileName;
}
}
}
Thanks :)
Re: QT plugins: a plugin that is a GUI
I've never programmed with plugins, but this may be the reason your check fails:
bool QPluginLoader::load ()
Loads the plugin and returns true if the plugin was loaded successfully; otherwise returns false. Since instance() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the plugin loaded in advance, in which case you would use this function.
Re: QT plugins: a plugin that is a GUI
Uhm ... probably you're right but look at qt's doc (4.5):
Quote:
QPluginLoader::QPluginLoader ( const QString & fileName, QObject * parent = 0 )
Constructs a plugin loader with the given parent that will load the plugin specified by fileName.
To be loadable, the file's suffix must be a valid suffix for a loadable library in accordance with the platform, e.g. .so on Unix, - .dylib on Mac OS X, and .dll on Windows. The suffix can be verified with QLibrary::isLibrary().
I understand that the plugin is loaded by the constructor so, if it fails here, why does it work in the method instance() :confused:
Re: QT plugins: a plugin that is a GUI
Either way the plugin object shouldn't inherit QWidget. It should create one when asked for it. I suspect this is not the case here.
Re: QT plugins: a plugin that is a GUI
That was exactly my problem explained in the other thread.
Acutally my plugin's main class inherits from QGraphicsView
as I have to paint all by my self ... I cannot use the normal qt's objects because when they blink (using stylesheet) the cpu's usage is around 90% :crying: