Results 1 to 9 of 9

Thread: Trouble with plugin system's documentation

  1. #1
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Trouble with plugin system's documentation

    Hello
    I'm trying to implement dynamic loading of plugins. But I ran into trouble.
    The plugin compiles, but I cannot load it.

    I've been reading http://doc.trolltech.com/4.3/plugins-howto.html over and over(section "The Lower-Level API: Extending Qt Applications"), but I don't get what's wrong!
    Been taking a look at the examples echo server and plug and paint too.

    I am confused about the checklist:
    Making an application extensible through plugins involves the following steps:
    Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins.
    Use the Q_DECLARE_INTERFACE() macro to tell Qt's meta-object system about the interface.
    Use QPluginLoader in the application to load the plugins.
    Use qobject_cast() to test whether a plugin implements a given interface.
    Writing a plugin involves these steps:

    Declare a plugin class that inherits from QObject and from the interfaces that the plugin wants to provide.
    Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces.
    Export the plugin using the Q_EXPORT_PLUGIN2() macro.
    Build the plugin using an suitable .pro file.
    Under "Writing a plugin involves these steps" I'm wondering about the 3rd point. This is not used in the example code a few lines down.
    Anyways I tried using it. I include <QtPlugin> and then use it in my plugin implementation.

    I did a small example with my problem:
    PluginInterface.h http://pastebin.com/m570b0214
    PluginExample.h http://pastebin.com/m76fa2ca6
    PluginExample.cpp http://pastebin.com/m699b7259
    My .pro-file http://pastebin.com/m4bac5157

    There probably is something I'm missing but I still get the feeling the documentation is wrong here? There's a semicolon missing after Q_DECLARE_INTERFACE in the interface example, and if you check out the documentation for 4.5 that line is missing completely even though it seems its still necessary to use in 4.5?

    I'm using Qt 4.3 on Mac OS X. Would be very helpful if someone could help me out. I'm stuck

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

    Default Re: Trouble with plugin system's documentation

    Please don't link to code pasted on 3rd party sites. It tends to disappear over time and the forum thread becomes practically useful. Instead use the attachment feature of the forum.
    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
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trouble with plugin system's documentation

    Quote Originally Posted by wysota View Post
    Please don't link to code pasted on 3rd party sites. It tends to disappear over time and the forum thread becomes practically useful. Instead use the attachment feature of the forum.
    You're right. The files are attached to this post.
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with plugin system's documentation

    Typical errors encountered on plugins load (may or may not be relevant in your case) :

    • the shared library export symbols that are not actually implemented leading to an error upon symbol resolution which on some systems prevent the shared library from being loaded at all (probably not relevant here given your code)
    • the plugin and the application that attempt to load are not compiled against the same version of Qt. You should pay particular attention to the build mode (release or debug). It must be the same for the app and the plugins AFAIK.

    A good way to determine what's wrong is to load the shared lib by hand using QLibrary instead of QPluginLoader and to watch the console output to see if relevant messages are displayed. Now this won't load the actual plugin class for you but it should give an explaination if loading fails.
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trouble with plugin system's documentation

    Thank you. I've gotten the plugin to load now. Can't figure out what was wrong though, but I dead a clean project in QtCreator and now it works. Have not been able to reproduce the problem.

    But now I cannot call member functions on the object. Getting bus error

    What Im doing is I create a QPluginLoader object for my plugin, make sure it is loaded, get the instance using instance() and then typecast it with qobject_cast to my interface class. Cannot see what I'm doing wrong.

    See attached file which is a small test case.
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with plugin system's documentation

    Quote Originally Posted by niklas View Post
    Thank you. I've gotten the plugin to load now. Can't figure out what was wrong though, but I dead a clean project in QtCreator and now it works. Have not been able to reproduce the problem.
    Things like that happen sometimes. It usually comes from the way qmake dependency handling accross subdirs (or lack thereof). When you change a header file for your interface the plugin won't be recompiled unless that file appears in the HEADERS variable of the plugin project file.

    Quote Originally Posted by niklas View Post
    But now I cannot call member functions on the object. Getting bus error

    See attached file which is a small test case.
    Actual console output and/or full code (including plugin) would help.
    Current Qt projects : QCodeEdit, RotiDeCode

  7. #7
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trouble with plugin system's documentation

    I am still stuck with this problem
    Not getting bus error though, but the app unexpectedly quits.

    My code is here: http://rafb.net/p/AvStNW98.html
    Quitting when reaching line 22 where I call a function in the plugin.

    The full console output from running the app is:
    Starting /Users/niklas/code/test/PluginLoadingTest/PluginLoadingTest...
    plugin loaded!

    The program has unexpectedly finished.

  8. #8
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trouble with plugin system's documentation

    I just now got it to work. Even though it seemed as if it was successfully loaded it was not. I checked if instance() was null and it was not, but the error string was not empty - it said the build key differed.
    It differed even though I had recompiled both the plugin and the app since I updated to Qt 4.5.

    I tried removing the plugin binary and it worked - solved my problem!
    Wonder what I did wrong in QtCreator when trying to recompile...

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

    Default Re: Trouble with plugin system's documentation

    Please stop storing your code on external sites.
    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.


Similar Threads

  1. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 15:13

Tags for this Thread

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.