Hi,

can I instantiate multiple object of a plugin class?
I show you a prototype of code I'd like to use

Qt Code:
  1. QPluginLoader loader (pluginDir.absoluteFilePath (fileName));
  2.  
  3. QObject *instance = loader.instance ();
  4. QObject *newObj = 0;
  5. QMetaObject *mo = 0;
  6. if (instance) {
  7. IExample *plugin = qobject_cast<IExample*>(instance);
  8. if (plugin) {
  9. qDebug() << instance->metaObject ()->className () << "plugin says:"
  10. << plugin->messageString ();
  11.  
  12. newObj = instance->metaObject ()->newInstance (0);
  13. if (0 != newObj)
  14. qDebug () << "Create New Instance OK";
  15. else
  16. qDebug () << "Create New Instance Failed";
  17. }
  18. }
To copy to clipboard, switch view to plain text mode 

where IExample is defined

Qt Code:
  1. class IExample
  2. {
  3. public:
  4. virtual ~IExample () {}
  5.  
  6. virtual QString messageString () const = 0;
  7. };
  8.  
  9. Q_DECLARE_INTERFACE (IExample, "local.costa.IExample/1.0")
To copy to clipboard, switch view to plain text mode 

and this is the loaded plugin

Qt Code:
  1. class HelloWorldPlugin: public QObject, IExample
  2. {
  3. Q_OBJECT
  4. Q_INTERFACES (IExample)
  5.  
  6. public:
  7. HelloWorldPlugin(QObject *parent = 0);
  8.  
  9. QString messageString () const;
  10. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. HelloWorldPlugin::HelloWorldPlugin(QObject *parent)
  2. : QObject (parent)
  3. {
  4. }
  5.  
  6. QString HelloWorldPlugin::messageString() const
  7. {
  8. return QString("Hello World");
  9. }
  10.  
  11. Q_EXPORT_PLUGIN2 (HelloWorldPlugin, HelloWorldPlugin)
To copy to clipboard, switch view to plain text mode 

the output is

Qt Code:
  1. HelloWorldPlugin plugin says: "Hello World"
  2. Create New Instance Failed
  3. Found 1 entries
To copy to clipboard, switch view to plain text mode