Results 1 to 12 of 12

Thread: Plugin interface with slots and signals

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Plugin interface with slots and signals

    Some things:
    is the private inheritance of the interface class by accident?
    you plugin implementation is missing the signals: section.
    does GetWidget() return a valid widget pointer?
    if yes, why don't you use that in the connect?

    Cheers,
    _

  2. #2
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Plugin interface with slots and signals

    Since you are requiring that all of the plugins have a MessageSend signal, just derived your initial plugin interface from QObject and include the signal there
    Qt Code:
    1. class PluginWidgetInterface : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. virtual ~PluginWidgetInterface() {}
    6. virtual QWidget * GetWidget() = 0;
    7. signals:
    8. void MessageSend();
    9. };
    To copy to clipboard, switch view to plain text mode 
    You will still need to use Q_OBJECT in your derived classes
    Qt Code:
    1. class Plugin1 : public PluginWidgetInterface
    2. {
    3. Q_OBJECT
    4. Q_PLUGIN_METADATA(IID "myplugins.Plugin1")
    5. Q_INTERFACES(PluginWidgetInterface)
    6. public:
    7. ~Plugin1() {}
    8. QWidget * GetWidget();
    9. };
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Plugin interface with slots and signals

    Quote Originally Posted by mcarter View Post
    Since you are requiring that all of the plugins have a MessageSend signal, just derived your initial plugin interface from QObject and include the signal there
    Ok, I derived interface class from QObject. Now, when I compile plugin dll I get lots of errors like:
    error: undefined reference to `PluginWidgetInterface::qt_metacast(char const*)

    I guess I have to put interface class in different library and link in statically with all plugins dlls but it looks too complicated
    Last edited by folibis; 9th September 2013 at 22:50.

  4. #4
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Plugin interface with slots and signals

    As long as you are not linking against a statically built Qt then everythign should work fine.
    The following code builds plugin lib in linux, and I think should build proper dll in windows

    Qt Code:
    1. #ifndef _PLUGIN_WIDGET_INTERFACE_H_
    2. #define _PLUGIN_WIDGET_INTERFACE_H_
    3.  
    4. #include <QtPlugin>
    5. #include <QObject>
    6.  
    7. class PluginWidgetInterface : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. virtual ~PluginWidgetInterface() {}
    12. virtual QWidget * GetWidget() = 0;
    13. signals:
    14. void MessageSend();
    15. };
    16.  
    17. #define PluginWidgetInterface_iid "myplugins.PluginWidgetInterface"
    18. Q_DECLARE_INTERFACE(PluginWidgetInterface, PluginWidgetInterface_iid)
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef _PLUGIN1_H_
    2. #define _PLUGIN1_H_
    3.  
    4. #include "plugininterface.h"
    5.  
    6. class Plugin1 : public PluginWidgetInterface
    7. {
    8. Q_OBJECT
    9. //Q_PLUGIN_METADATA(IID "myplugins.Plugin1")
    10. Q_INTERFACES(PluginWidgetInterface)
    11. public:
    12. ~Plugin1() {}
    13. QWidget * GetWidget();
    14. };
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "plugin1.h"
    2.  
    3. QWidget * Plugin1::GetWidget()
    4. {
    5. return 0;
    6. }
    7.  
    8. Q_EXPORT_PLUGIN2(plugin1, Plugin1);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. TEMPLATE = lib
    2. TARGET =
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. # Input
    7. HEADERS += plugin1.h plugininterface.h
    8. SOURCES += plugin1.cpp
    To copy to clipboard, switch view to plain text mode 

    Can then be used with
    Qt Code:
    1. QPluginLoader loader( qstrLibFilename );
    2. PluginWidgetInterface * plugin = qobject_cast<PluginWidgetInterface *>(loader.instance());
    3. QWidget * widget = plugin->GetWidget();
    4. connect(plugin,SIGNAL(MessageSend()),this,SLOT(MessageReceived()));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to mcarter for this useful post:

    folibis (10th September 2013)

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.