Results 1 to 7 of 7

Thread: QT plugins: a plugin that is a GUI

  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ...

    Actually I have a main.cpp that creates and executes a QApplication
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. MainApp app(argc, argv);
    4. return app.exec();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class MainApp : public QApplication
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainApp(int &argc, char **argv);
    7. ~MainApp();
    8.  
    9. private:
    10. void loadPlugins();
    11.  
    12. QDir pluginsDir;
    13. QStringList pluginFileNames;
    14. }
    To copy to clipboard, switch view to plain text mode 

    when MainApp is created it calls loadPlugins:
    Qt Code:
    1. MainApp::MainApp(int &argc, char **argv) :
    2. QApplication(argc, argv)
    3. {
    4. loadPlugins();
    5. }
    To copy to clipboard, switch view to plain text mode 

    QPluginLoader loader(..) fails as I get:
    ERROR !!! loader.isLoaded(): <0> - loader.errorString(): <Unknown error>
    Does anybody know something about it ?
    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT plugins: a plugin that is a GUI

    What is the contents of your loadPlugins() method?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ) 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:

    Qt Code:
    1. void MainApp::loadPlugins()
    2. {
    3. pluginsDir = QDir(qApp->applicationDirPath());
    4. pluginsDir.cd("plugins");
    5.  
    6. foreach (QString fileName, pluginsDir.entryList(QDir::Files))
    7. {
    8. QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
    9.  
    10. //if ( ! loader.isLoaded() )
    11. //{
    12. // puts("ERROR: plugin not loaded !");
    13. // return;
    14. //}
    15.  
    16. QObject *plugin = loader.instance();
    17. if (plugin)
    18. {
    19. BaseInterface * b = qobject_cast<BaseInterface*>(plugin);
    20. if (b)
    21. {
    22. puts("Plugin loaded - setting config file ...");
    23. b->SetConfigFileName("objects.xml");
    24. puts("Starting plugin ...");
    25. b->Start();
    26. }
    27. else
    28. {
    29. puts("ERROR: Could not convert Plugin !!! ");
    30. }
    31. pluginFileNames += fileName;
    32. }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

  4. #4
    Join Date
    Mar 2007
    Posts
    57
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  5. #5
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT plugins: a plugin that is a GUI

    Uhm ... probably you're right but look at qt's doc (4.5):

    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()

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Qt Code:
    1. class KofaGuiDev : public QGraphicsView
    2. ...
    To copy to clipboard, switch view to plain text mode 
    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%

Similar Threads

  1. Trouble with plugin system's documentation
    By niklas in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2009, 22:07
  2. Replies: 1
    Last Post: 31st October 2008, 14:35
  3. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  4. Qt Plugins Error
    By nathanpackard in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 23:19
  5. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.