Results 1 to 10 of 10

Thread: QPluginLoader Qt 4

  1. #1
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QPluginLoader Qt 4

    I'm trying to load a custom plugin into an app I am making. This plugin isn't made for QtDesigner, it simply extends the functionality of an existing app. The problem is when I try to load the dll using QPluginLoader, isLoaded is always returing false. Not matter what I try. Here is my current attempts.

    Here is my code
    #include "main_frmPE.h"

    main_frmPE::main_frmPE (QWidget * parent) :
    QWidget (parent)
    {
    setupUi (this);
    QPluginLoader menu (QApplication::applicationDirPath() + "/../lib/menu.dll");
    if (menu.isLoaded ())
    QMessageBox::information (this, "Info","Hello World");
    else
    QMessageBox::information (this, "Info","Yuk!!");

    }

    This is the plugin interface
    // Define Qt definitions
    #include <QtGui>

    class Plugin_Interface
    {
    public:
    virtual ~Plugin_Interface () {}
    virtual void init () {}
    virtual void run () {}
    };

    Q_DECLARE_INTERFACE (Plugin_Interface, "plugin.programmerseditor.menu/1.0");


    and this is the plugin itself

    // Define Qt definitions
    #include <QtGui>

    // Define plugin definitions
    #include "../../main/plugins/plugin_interface.h"

    class plugin_menu_interface:
    public QObject, public Plugin_Interface
    {
    Q_OBJECT
    Q_INTERFACES (Plugin_Interface)

    public:
    plugin_menu_interface ();
    virtual ~plugin_menu_interface ();
    void init () {}
    void run () {}
    };


    // Define user definitions
    #include "menu_interface.h"

    plugin_menu_interface:lugin_menu_interface ()
    {
    qDebug ("Hello World");
    }

    plugin_menu_interface::~plugin_menu_interface ()
    {

    }



    I guess the most useful thing would be some working example code on how to do this. Qt's documentation is terrible on this subject. Otherwise, if someone know what I am doing wrong, or has any hints please let me know. I have spent days on this and have had no luck. And I can't find any working code to use as an example. Thanks everyone

    Rian

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader Qt 4

    Quote Originally Posted by rianquinn
    ...
    main_frmPE::main_frmPE (QWidget * parent) :
    QWidget (parent)
    {
    ...
    QPluginLoader menu (QApplication::applicationDirPath() + "/../lib/menu.dll");
    ...
    }
    ...
    Just use "../lib/menu.dll" - without appDirPath. Is the dll really there? Try to run the exe from command line, so that ../lib/menu.dll is that dll.
    Do you use another build system as qmake?
    Try to load your plugin with one of the plugandpaint sample. It will produce two different errors depending on what failed: Your plugin is not a "valid" plugin or it doesn't implement any of the interfaces. If it only does not implement any of the interfaces it should work with your application...

    I had many headaches with the plugin system - finally decided to use my own. So good luck...
    It comes down to the fact that Qt 4 denies to load plugins which were not compiled with the same compiler, Qt 4 library version (debug / release) and maybe much more. The worst thing about that is, that you don't get any useful information about the problem.
    If you have much time install the Qt 4 debug with the source code and debug the constructor call of QPluginLoader by stepping into that call. Then you can try to figure out where the problem is.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader Qt 4

    I'm trying to load a custom plugin into an app I am making. This plugin isn't made for QtDesigner, it simply extends the functionality of an existing app.
    I think it would be better for you to use QLibrary class indstead.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader Qt 4

    Your CPP file of the plugin needs to define:

    Q_EXPORT_PLUGIN2(PluginClassName, NameOfLibrary)

    I don't see that in your sample code for the plugin.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader Qt 4

    I don't know if you have looked at this sample. It worked for me:

    http://doc.trolltech.com/4.1/tools-p...asictools.html

  6. #6
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader Qt 4

    Thanks for your replies, The Q_EXPORT_PLUGIN2 didn't work.

    Can't use QLibrary. This would require me to extern all my interfaces to "C" code which can't be done. Also, the QPluginLoader is new to Qt 4, which adds a much needed Interface Layer to plugins that should become the future of all Qt programming. This is something (in my opinion) that should be figured out instead of avoiding.

    So far no luck. I am currently working with Troll Tech to figure out what is wrong. It has to be something simple. At this point, sample code is going to be the most useful thing. Has anyone actually gotten this to work. Is there an open source example, that I can diff with my code.

    Thanks Guys for all of your help. I would like to be able to post a complete solution to this thread to help others in the future.

    Rian

  7. #7
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader Qt 4

    Ok,

    Here is the solution!!! YEAH

    Q_EXPORT_PLUGIN2 needs to be in the following format.

    Q_EXPORT_PLUGIN2(TARGET, INTERFACE)

    TARGET is the name of the library (meaning in your .pro file, you specify the output file name by using the variable TARGET). Mine should have been "menu".

    INTERFACE is the name of the interface that you are using. Mine is plugin_interface

    Finally, the constructor of the QPluginLoader, simply specifies the plugin file name and path. You still have to run the load function.

    If anyone needs an example of this code, you can look at the open source "Programmers Editor" on source forge.

    Rian

  8. #8
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QPluginLoader Qt 4

    Quote Originally Posted by rianquinn
    ...snip...
    If anyone needs an example of this code, you can look at the open source "Programmers Editor" on source forge.
    Rian
    Got a URL?
    I searched for "Programmers Editor" on source forge and the only project by that name was using Python. There are lots of "Programmers something Editor". Which one are you?

  9. #9
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader Qt 4

    programmersedit.sourceforge.net, however code won't be available until this summer when I have more time (college student). However, the surrent code is working really good. Qt 4's model view architecture is amazing for such a concept.

    Thanks

  10. #10
    Join Date
    Sep 2006
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader Qt 4

    Quote Originally Posted by rianquinn View Post
    Q_EXPORT_PLUGIN2(TARGET, INTERFACE)

    [...]

    INTERFACE is the name of the interface that you are using. Mine is plugin_interface
    shouldn't INTERFACE be 'plugin_menu_interface'? from the plug&paint example:

    Qt Code:
    1. Q_EXPORT_PLUGIN2(pnp_basictools, BasicToolsPlugin)
    To copy to clipboard, switch view to plain text mode 

    where BasicToolsPlugin header is:

    Qt Code:
    1. class BasicToolsPlugin : public QObject,
    2. public BrushInterface,
    3. public ShapeInterface,
    4. public FilterInterface
    To copy to clipboard, switch view to plain text mode 

    Using 'plugin_interface' in Q_EXPORT_PLUGIN2 will make the compiler complain as the macro will try to create an instance of the plugin_interface class which cannot be instantiated as being pure virtual.

    G.

    PS anyway I cannot make it work nor cannot debug QPluginLoader..trolltech should do something about that, who can I complain with?

Similar Threads

  1. QPluginLoader doesn't load plugin
    By BeS in forum Qt Programming
    Replies: 6
    Last Post: 26th November 2008, 19:12
  2. QPluginLoader instance
    By Jeff100 in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 06:47
  3. QPluginLoader question
    By QPlace in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2007, 11:16
  4. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  5. QPluginLoader fails when using "debug" config
    By paradiza in forum Qt Programming
    Replies: 22
    Last Post: 14th February 2007, 06:59

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.