I am developing under Windows and I have a Qt plugin project that produces a dll, and I have another app that can load that dll dynamically as a plugin via the usual Qt methods. Basically what I wanted to do was have the plugin report its status back to this app that's using it (i.e. the plugin emits a signal, the app receives it via a slot). So after I successfully detect and read in the plugin (i.e. the dll file), I do the usual connect call to set up the signal/slot (which returns true), but the connection doesn't seem to actually be working, as my slot code never gets executed in the app. I tried to strip down the pertinent code below.


UpgradeInterface.h (this is the interface a plugin extends):

Qt Code:
  1. class UpgradeInterface : public QObject
  2. {
  3. public:
  4.  
  5. virtual ~UpgradeInterface() {}
  6. virtual bool performUpgrade() = 0;
  7.  
  8. signals:
  9. void statusUpdate(QString statusMsg);
  10. };
  11.  
  12. Q_DECLARE_INTERFACE(UpgradeInterface, "com.UpgradeInterface/1.0")
To copy to clipboard, switch view to plain text mode 

//----------------------------------------------------------

UpgradePlugin.h:

Qt Code:
  1. class UpgradePlugin : public QObject, public UpgradeInterface
  2. {
  3. Q_OBJECT
  4. Q_INTERFACES(UpgradeInterface)
  5.  
  6. public:
  7. bool performUpgrade();
  8.  
  9. signals:
  10. void statusUpdate(QString statusMsg);
  11. };
To copy to clipboard, switch view to plain text mode 

//----------------------------------------------------

UpgradePlugin.cpp:

Qt Code:
  1. bool UpgradePlugin::performUpgrade()
  2. {
  3. emit statusUpdate("Upgrade started!");
  4. return true;
  5. }
  6.  
  7. Q_EXPORT_PLUGIN2(UpgradePlugin, UpgradePlugin)
To copy to clipboard, switch view to plain text mode 

//-------------------------------------------------

The following is part of the app code that detects/loads the plugin.

MyDialog.h:

Qt Code:
  1. class MyDialog : public QDialog
  2. {
  3. Q_OBJECT
  4. //...
  5. //...
  6. protected slots:
  7. void statusUpdateFromUpgradePlugin(QString statusMsg);
  8. };
To copy to clipboard, switch view to plain text mode 

//------------------------------------------------------

MyDialog.cpp:

Qt Code:
  1. void MyDialog::loadPlugins(QDir dir)
  2. {
  3. // Load dynamic plugins
  4.  
  5. foreach (QString fileName, dir.entryList(QDir::Files))
  6. {
  7. QPluginLoader loader(dir.absoluteFilePath(fileName));
  8. QObject *plugin = loader.instance();
  9.  
  10. if (plugin)
  11. {
  12. UpgradeInterface * iUpgrade = qobject_cast<UpgradeInterface *>(plugin);
  13. if (iUpgrade)
  14. {
  15. bool success = connect(iUpgrade, SIGNAL(statusUpdate(QString)), this, SLOT(statusUpdateFromUpgradePlugin(QString))); // returns true
  16. iUpgrade->performUpgrade();
  17. }
  18. }
  19. }
  20. }
  21.  
  22. void MyDialog::statusUpdateFromUpgradePlugin(QString statusMsg)
  23. {
  24. cout << statusMsg; // Never gets here!
  25. }
To copy to clipboard, switch view to plain text mode