Results 1 to 3 of 3

Thread: Loading QWidgets as a Plugin

  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Loading QWidgets as a Plugin

    I'm working on a plugin interface, which will be used to load a set of QWidgets into a host application. Currently, the interface provides a getWidget() method, which returns an instance to the widget. This method sounds obvious enough, but the problem lies in how the host application is handling the widgets. The host application only knows how to manage QWidget instances and not instances to a plugin's interface, thus losing access to other methods in the interface.

    I have been able to solve this by having the interface class inherit QWidget. Subclassing QWidget ensures the interface methods are retained by the host application's widget manager.

    See examples below...

    First method:
    class MyInterface1 {
    public:
    virtual void someMethod() = 0;
    virtual QWidget* getWidget() = 0;
    };

    class MyPlugin1 : public QWidget, public MyInterface1 {
    public:
    void someMethod();
    QWidget* getWidget();
    };


    Second method:
    class MyInterface2 : public QWidget {
    public:
    virtual void someMethod() = 0;
    };

    class MyPlugin2 : public MyInterface2 {
    public:
    void someMethod();
    };


    My problem with this is that by subclassing QWidget, my interface class has wandered beyond the scope of being a pure plugin interface. Anyone else think there is a better approach?

    Apologies if I may have confused anyone

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Loading QWidgets as a Plugin

    I'm not entirely sure what you're trying to do here, but the canonical way to have a plugin that also supports signals and slots or other QWidget-y properties is to create a wrapper class that is pure virtual, and contains a single function that returns an instance of the class/widget you're interested in. If you return a pointer to a base class, you can have a full-blown interface and inheritance hierarchy returned, and provide simple wrappers for all of them. The returned class is just a class - not a plugin. It is simply made accessible through the wrapper, which is a plugin.

  3. The following user says thank you to SixDegrees for this useful post:

    aylek (25th May 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading QWidgets as a Plugin

    Quote Originally Posted by SixDegrees View Post
    I'm not entirely sure what you're trying to do here, but the canonical way to have a plugin that also supports signals and slots or other QWidget-y properties is to create a wrapper class that is pure virtual, and contains a single function that returns an instance of the class/widget you're interested in. If you return a pointer to a base class, you can have a full-blown interface and inheritance hierarchy returned, and provide simple wrappers for all of them. The returned class is just a class - not a plugin. It is simply made accessible through the wrapper, which is a plugin.
    Thanks, I wasnt sure if casting an instance of a QWidget (using qobject_cast<>) would work, since normally one would cast the instance returned by QPluginLoader::instance(). I just tested it, and sure enough, casting the QWidget instance exposed the complete plugin interface. Thanks for your help!

Similar Threads

  1. Loading SQLite plugin. Again!
    By miwarre in forum Newbie
    Replies: 5
    Last Post: 12th November 2009, 10:23
  2. ODBC Database plugin is not loading
    By QPlace in forum Qt Programming
    Replies: 11
    Last Post: 4th November 2008, 15:04
  3. Plugin Loading and Signal Handling in Qt4
    By liquid in forum Newbie
    Replies: 4
    Last Post: 25th January 2008, 09:53
  4. How to debug plugin loading?
    By yosefm in forum Qt Tools
    Replies: 1
    Last Post: 1st November 2007, 12:02
  5. plugin loading problem
    By naresh in forum Qt Programming
    Replies: 6
    Last Post: 9th June 2007, 19:05

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.