Results 1 to 2 of 2

Thread: QtPlugins how to communicate between plugins?

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

    Default QtPlugins how to communicate between plugins?

    Hello,

    i'm working on a program which has a QMdiArea. The QMdiSubWindows are QPlugins which can be loaded during runtime.

    This is the current plugin Interface:

    Qt Code:
    1. #ifndef INTERFACE_H
    2. #define INTERFACE_H
    3.  
    4. #include <QtPlugin>
    5.  
    6. class PluginInterface
    7. {
    8. public:
    9. virtual ~PluginInterface() { }
    10.  
    11. virtual QString getName() = 0;
    12. virtual QWidget* getWidget() = 0;
    13.  
    14. };
    15.  
    16. Q_DECLARE_INTERFACE(PluginInterface, "foo.demo.PluginInterface/1.0")
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    in getWidget() i load or create a widget and than the main program can get the widget with getWidget() and put it into a QMdiSubWindow.

    So far it works quite well.

    But now i want to have some communication between the plugins. E.g. if i press a button in one plugin something should happen in the other plugin.

    I have tried to give the plugins a reference to their communication partner when i load a plugin. But it doesn't work. I think the problem was that i always casted the plugins down to qwidget and than within the plugin again up to foobar-plugin but than of course all the special foobar-plugin methods are lost due the "down-cast". But the main program doesn't know about all possible plugin classes. So i'm stuck and don't know how to solve the problem.

    Can you give me some hints how i could achieve this?

    Thanks!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtPlugins how to communicate between plugins?

    Give the central class (the mdi window, perhaps) a method getPlugin(QString) or so.
    Have that method return the pointer to the plugins common base class (or NULL, if the plugin/window is not present).
    Cast that pointer at the calling plugin to the required type of the other plugin. Then just call the regular method.
    That way the plugins know about each other... but, if you want to call methods, they obviously can't be completely independent, so that probably is ok.

    HTH

Similar Threads

  1. Qt Plugins Error
    By nathanpackard in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 23:19
  2. Qt4 Plugins How-to
    By Chaid in forum Qt Programming
    Replies: 4
    Last Post: 8th July 2006, 08:32

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.