Use plauginLoader as a dedicated static object.

This commit is contained in:
Gerhard Hoffmann 2023-09-10 16:51:07 +02:00
parent 38e79f0354
commit ff418b11a1

View File

@ -40,6 +40,8 @@ static const QMap<QString, int> baudrateMap = {
{"57600" , 4}, {"115200" , 5} {"57600" , 4}, {"115200" , 5}
}; };
QPluginLoader Update::pluginLoader;
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) { hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
hwinf *hw = nullptr; hwinf *hw = nullptr;
if (plugInDir.exists()) { if (plugInDir.exists()) {
@ -48,7 +50,8 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
QFileInfo info(pluginLibName); QFileInfo info(pluginLibName);
if (info.exists()) { if (info.exists()) {
pluginLibName = plugInDir.absoluteFilePath(pluginLibName); pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
static QPluginLoader pluginLoader(pluginLibName); pluginLoader.setFileName(pluginLibName);
// static QPluginLoader pluginLoader(pluginLibName);
if (!pluginLoader.load()) { if (!pluginLoader.load()) {
qCritical() << "in directory" << plugInDir.absolutePath(); qCritical() << "in directory" << plugInDir.absolutePath();
qCritical() << "cannot load plugin" << pluginLoader.fileName(); qCritical() << "cannot load plugin" << pluginLoader.fileName();
@ -80,6 +83,21 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
return hw; return hw;
} }
bool Update::unloadDCPlugin() {
if (pluginLoader.unload()) {
qCritical() << "unloaded plugin" << pluginLoader.fileName();
// Note: will re-instantiate the library !
// QObject *rootObject = pluginLoader.instance();
// if (rootObject) {
// qCritical() << "reloaded plugin: root object again available";
// return false;
// }
// qCritical()unloaded plugin: root object gone";
return true;
}
return false;
}
Update::Update(hwinf *hw, Update::Update(hwinf *hw,
Worker *worker, Worker *worker,
QString customerRepository, QString customerRepository,