Results 1 to 20 of 23

Thread: QPluginLoader fails when using "debug" config

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question QPluginLoader fails when using "debug" config

    Hi,

    I'm using Qt 4.2.1 on Debian (etch) and I try to build a few plugins to extend my app's functionality. The problem I have is that QPluginLoader won't load my plugin if I compile the plugin (and the app of course) with "CONFIG += debug". In this case a subsequent QPluginLoader::errorString() just returns "Unknown Error".

    However, when I leave CONFIG blank or set it to "release" all works flawlessly. The same behaviour can be witnessed when I try the official example code "plugandpaint" - the static library is loaded by the application but the dynamic library isn't.

    Due to this I think that this is not related to my code but to Qt in general. Any idea?


    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    The first parameter of Q_EXPORT_PLUGIN2 macro must match the file name, so if there is "d" or "_debug" appended to plugin's name in debug mode, you have to make relevant change in your code.

  3. #3
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    True, but I'm using a static name as TARGET in my pro file. Even if I would use the dynamic version (as plugandpaint does)...

    Qt Code:
    1. contains(TEMPLATE,lib) {
    2. CONFIG(debug, debug|release) {
    3. mac:TARGET = $$member(TARGET, 0)_debug
    4. win32:TARGET = $$member(TARGET, 0)d
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    ... it would only be relevant for Windoze and Mac OS, right?

    As I'm using this .pro file...

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += plugin debug
    3. HEADERS += plugin.h
    4. SOURCES += plugin.cpp
    5. DESTDIR = ../bin/plugins
    6. TARGET = plugin
    To copy to clipboard, switch view to plain text mode 

    ... my usage of Q_EXPORT_PLUGIN2(plugin, Plugin) should be correct I think.

    para

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    ... my usage of Q_EXPORT_PLUGIN2(plugin, Plugin) should be correct I think.
    Yes, it should be OK in such situation.

    Nevertheless you could try Q_EXPORT_PLUGIN2(plugin_debug, Plugin) and rename your plugin to libplugin_debug.so.

  5. #5
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    I just tried it... doesn't work.

    Have a look at examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp. Even Trolltech uses a fixed value as target name in Q_EXPORT_PLUGIN2 although they consider the other host operating systems in their .pro file (see first code sample above). As stated above, adding debug to their CONFIG won't work either. Can you reproduce that on your machine? Maybe that gives us a clue...

    para
    Last edited by paradiza; 9th February 2007 at 22:54.

  6. #6
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    From the Qt docs:
    If you configure Qt to be built in both debug and release modes, but only build applications in release mode, you need to ensure that your plugins are also built in release mode. By default, if a debug build of Qt is available, plugins will only be built in debug mode. To force the plugins to be built in release mode, add the following line to the plugin's project file:
    CONFIG += release
    This will ensure that the plugin is compatible with the version of the library used in the application.
    What do they mean with the first sentence? Does the behaviour depend on the way Qt itself was built? I'm using the Debian package and hence have no influence on that I mean, as long as I set the same CONFIG values for the plugin and the app it should work, right?

    para

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    I mean, as long as I set the same CONFIG values for the plugin and the app it should work, right?
    Right .

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    Have a look at examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp. Even Trolltech uses a fixed value as target name in Q_EXPORT_PLUGIN2 although they consider the other host operating systems in their .pro file (see first code sample above).
    Maybe something changed in Qt 4.2, but Qt 4.1 was very picky about that first parameter.

    Quote Originally Posted by paradiza View Post
    As stated above, adding debug to their CONFIG won't work either. Can you reproduce that on your machine?
    I've just rebuilt both plugandpaint application and extrafilterplugin in debug mode and it seems to work OK.

  9. #9
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by jacek View Post
    Maybe something changed in Qt 4.2, but Qt 4.1 was very picky about that first parameter.

    I've just rebuilt both plugandpaint application and extrafilterplugin in debug mode and it seems to work OK.
    Which Qt version and which OS are you using? Do you see libpnp_extrafilters.so being listed in the plugin dialog?

    Thanks

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    Which Qt version and which OS are you using?
    Qt 4.2.2 under PLD Linux.

    Quote Originally Posted by paradiza View Post
    Do you see libpnp_extrafilters.so being listed in the plugin dialog?
    Yes and I can use those filters.

    Did you add CONFIG += debug in extrafilters.pro or in plugandpaintplugins.pro (I did in the first one)?

  11. #11
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    I set it in
    1. basictools.pro (added "debug")
    2. extrafilters.pro (added "debug")
    3. plugandpaint.pro (added "CONFIG += debug")


    Didn't you change plugandpaint.pro?

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

    Default Re: QPluginLoader fails when using "debug" config

    Make sure that all components are built either in debug or release modes. Qt, plugin and your app should all be linked against each other (specifically the plugin should be built against the same version (debug or release) of Qt libraries). If in doubt, use ldd to check if the application and the plugin are linked against the same files when it comes to Qt dependency.

  13. #13
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by wysota View Post
    Make sure that all components are built either in debug or release modes. Qt, plugin and your app should all be linked against each other (specifically the plugin should be built against the same version (debug or release) of Qt libraries). If in doubt, use ldd to check if the application and the plugin are linked against the same files when it comes to Qt dependency.
    So you confirm what jacek says: if my Qt installation was built with "-release" instead of "-debug-and-release" there will never be a chance to compile my app and its plugins in debug mode because the Qt libs are not available for that mode, right?

    How could they design such a dependency? I understand that the plugin verification needs to ensure that app and plugin have to be compiled the same way, but it should not care about Qt itself in my opinion...

    para

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    Didn't you change plugandpaint.pro?
    Yes I did.

    I've built my Qt version in debug_and_release mode --- maybe that's why it works on my system?

  15. #15
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Possibly. In this case the Qt docs would make more sense to me but I still wouldn't understand Trolltech for creating a dependency to the Qt build process itself!
    Can one determine how a given Qt installation was build...?

    On the other hand it still seems to me that this is unrelated to my problem as the configure option appears to be applicable for Mac OS only:
    -debug-and-release . Compile and link two versions of Qt, with and without debugging turned on. [Mac only]
    Maybe it's time for an official bug report to clarify this...?

    para
    Last edited by paradiza; 10th February 2007 at 09:29.

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
  •  
Qt is a trademark of The Qt Company.