I use QFuture and QtConcurrent to manage threads in my application. Recently, I have decided to make my app more modular and therefore I adapted QtPlugin mechanism. I have interface used both in lib and application:
class IPlugin {
public:
virtual ~IPlugin() {}
virtual void run() {}
};
#define Plugin_iid "org.qt-project.Qt.Plugin.IPlugin"
Q_DECLARE_INTERFACE(IPlugin, IPlugin_iid)
}
I also have class Plugin in lib which inherits everything from class IPlugin:
class Plugin : public QObject, IPlugin {
Q_OBJECT
Q_INTERFACES(IPlugin)
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Plugin.IPlugin" FILE "Plugin.json")
public:
Plugin();
void run() Q_DECL_OVERRIDE;
};
The problem is that I can't start new thread using QtConcurrent without specifying address of a function:
QObject *plugin = pluginLoader.instance();
if (plugin) {
obj = qobject_cast<IPlugin *>(plugin);
if (obj) {
obj = QtConcurrent::run(*obj, &IPlugin::run);
}
}
Specifying base class address here does not help becouse base class method is invoked in that case. Is there a better way to solve that problem then including inherited header into application code base? I would like to avoid that.
Aucun commentaire:
Enregistrer un commentaire