Results 1 to 12 of 12

Thread: Plugin interface with slots and signals

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Plugin interface with slots and signals

    Now I work on application with plugins.
    So I have one interface and lots of plugins based on it:

    Qt Code:
    1. class PluginWidgetInterface
    2. {
    3. public:
    4. virtual ~PluginWidgetInterface() {}
    5. virtual QWidget * GetWidget() = 0;
    6. //---------------------------- SIGNALS ---------------------------
    7. virtual void MessageSend() = 0;
    8. };
    9.  
    10. #define PluginWidgetInterface_iid "myplugins.PluginWidgetInterface"
    11. Q_DECLARE_INTERFACE(PluginWidgetInterface, PluginWidgetInterface_iid)
    To copy to clipboard, switch view to plain text mode 

    and plugin implementation:
    Qt Code:
    1. #include "plugininterface.h"
    2.  
    3. class Plugin1 : public QObject,PluginWidgetInterface
    4. {
    5. Q_OBJECT
    6. Q_PLUGIN_METADATA(IID "myplugins.Plugin1")
    7. Q_INTERFACES(PluginWidgetInterface)
    8. public:
    9. ~Plugin1() {}
    10. QWidget * GetWidget();
    11. //---------------------------- SIGNALS ---------------------------
    12. void MessageSend();
    13. };
    To copy to clipboard, switch view to plain text mode 

    but at this point i have troubles with connect(). Because the Interface class not derived from QObject I cant use it with connect();
    If i cast it to QObject i get 0x0.

    Qt Code:
    1. QPluginLoader loader("plugin.dll");
    2. PluginWidgetInterface * plugin = qobject_cast<PluginWidgetInterface *>(loader.instance());
    3. QWidget * widget = plugin->GetWidget();
    4. QObject * o = dynamic_cast<QObject *>(plugin); // here o = NULL
    5. connect(o,SIGNAL(MessageSend),this,SLOT(MessageReceived));
    To copy to clipboard, switch view to plain text mode 

    I would like to do it in new style
    Qt Code:
    1. connect(o,&PluginWidgetInterface::MessageSend,this,&MainWindow::MessageReceived);
    To copy to clipboard, switch view to plain text mode 
    but i got error:
    no matching function for call to 'MainWindow::connect(QObject*&, void (PluginWidgetInterface::*)(), MainWindow* const, void (MainWindow::*)())


    So what is right way to define interface with signals to connect inheritance to slots?
    Last edited by folibis; 9th September 2013 at 11:28.

Similar Threads

  1. Replies: 2
    Last Post: 18th April 2013, 12:15
  2. Problem with plugin signals/slots
    By DiamonDogX in forum Qt Programming
    Replies: 8
    Last Post: 5th June 2009, 16:01
  3. Signals and Slots over interface
    By SnarlCat in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2009, 17:57
  4. Plugin-signals-slots problem
    By Misenko in forum Qt Programming
    Replies: 8
    Last Post: 23rd September 2008, 20:53
  5. Plugin interfaces, signals and slots
    By QPlace in forum Qt Programming
    Replies: 8
    Last Post: 9th August 2007, 21:19

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.