Results 1 to 1 of 1

Thread: qt signal in a Plugin base class

  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt signal in a Plugin base class

    I have created a GUI with a plugin system.
    There's a PluginInterface abstract class:

    Qt Code:
    1. class PluginInterface
    2. {
    3. virtual methods ...
    4. }
    To copy to clipboard, switch view to plain text mode 

    A plugin has a class like this:

    Qt Code:
    1. class TextValidatorPlugin : public QObject, public PluginInterface
    2. {
    3. Q_OBJECT
    4. Q_INTERFACES(DB_PluginSystem::PluginInterface)
    5. ...
    6.  
    7. signals:
    8. void PluginSaveSignal(const QString& pluginName, const QString& config);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Now the problem is in the loader:

    Qt Code:
    1. QPluginLoader loader(m_PluginsDir.absoluteFilePath(fileName));
    2.  
    3. QObject *plugin = loader.instance();
    4. if (plugin)
    5. {
    6. PluginInterface* pi = qobject_cast<PluginInterface*>(plugin);
    7. if (pi)
    8. {
    9. pi->SetParent(m_Parent);
    10. pi->SetMenu (pluginMenu);
    11. ...
    12. connect(pi , SIGNAL(PluginSaveSignal(const QString&, const QString&)),
    13. this, SLOT (PluginSaveSlot (const QString&, const QString&)));
    To copy to clipboard, switch view to plain text mode 

    The connect of course fails because the plugin loader knows only the base class (the interface) and not the class of the plugin.
    But I cannot put the signal in the base class as it's not inherited from QObject.
    And I cannot derive the plugin base class from QObject because the plugin classes (those derived from the plugin base class) already inherit from QObject...

    is there as solution for this ?


    Added after 11 minutes:


    Ok, solved by my self.
    Stupid me, I don't have to use PluginInterface* pi pointer but the QObject* plugin one in the connect.


    Added after 1 39 minutes:


    But there's still a problem:

    The plugin loader assumes that all the plugins have a signal
    Qt Code:
    1. void PluginSaveSignal(const QString&, const QString&)
    To copy to clipboard, switch view to plain text mode 
    but I cannot force who writes the plugins to implement it.

    I know it sounds weird, but is it possible somehow to create a signal pure virtual ?
    Like a:
    Qt Code:
    1. void PluginSaveSignal(const QString&, const QString&) = 0;
    To copy to clipboard, switch view to plain text mode 
    Last edited by trallallero; 17th November 2011 at 13:57.

Similar Threads

  1. Abstract base class and inherited class members
    By JovianGhost in forum General Programming
    Replies: 3
    Last Post: 19th March 2010, 12:32
  2. Replies: 3
    Last Post: 27th December 2008, 19:34
  3. Signal in base class Slot in Subclass
    By csvivek in forum Newbie
    Replies: 7
    Last Post: 30th March 2008, 16:59
  4. Connecting to a base class signal?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 22:37
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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.