Results 1 to 2 of 2

Thread: Dynamic widget plugin

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Dynamic widget plugin

    Hey there,

    I'd like to:
    - Load dynamically a low level Qt Plugin.
    - That plugin contains some unique widgets.
    - Then from my main application, I want to create and interact with that custom widget.

    Is it possible or do I have to create an abstract interface for all my custom widgets?

    Thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic widget plugin

    I think that your plugin can be abstract factory, so the interface can look like this:
    Qt Code:
    1. class Interface
    2. {
    3. public:
    4. QStringList availableWidgets() const = 0;
    5. QWidget * createWidgetForName(const QString & widgetName, QWidget * parent = 0) const = 0;
    6. };
    7.  
    8. // in plugin:
    9. class Plugin : public Interface
    10. {
    11. /* ... */
    12. };
    13.  
    14. QWidget * Plugin::createWidgetForName(const QString & widgetName) const
    15. {
    16. if (name == "WidgetOne")
    17. return new WidgetOne(parent);
    18. if (name == "WidgetTwo")
    19. return new WidgetTwo(parent);
    20. }
    To copy to clipboard, switch view to plain text mode 
    In such situation you can only declare that interface and made as many widgets as you want in you plugin shared library. The problem is that all the widgets you get as QWidget so you dont know anything about custom methods etc. So you have to include custom widgets headers in you main application and qobject_cast them.
    At least that is what I would do when I face your problem.

    P.S. Ohh, of course you can also use Property System and interact with widgets with property() and setProperty()
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    bunjee (30th April 2009)

Similar Threads

  1. Plugin with widget
    By Misenko in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2008, 20:55
  2. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  3. Replies: 4
    Last Post: 9th August 2007, 08:20
  4. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  5. Managing widget plugin in Qt Designer
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 31st January 2006, 09:58

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.