Use plauginLoader as a dedicated static object.
This commit is contained in:
parent
38e79f0354
commit
ff418b11a1
20
update.cpp
20
update.cpp
@ -40,6 +40,8 @@ static const QMap<QString, int> baudrateMap = {
|
||||
{"57600" , 4}, {"115200" , 5}
|
||||
};
|
||||
|
||||
QPluginLoader Update::pluginLoader;
|
||||
|
||||
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
||||
hwinf *hw = nullptr;
|
||||
if (plugInDir.exists()) {
|
||||
@ -48,7 +50,8 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
||||
QFileInfo info(pluginLibName);
|
||||
if (info.exists()) {
|
||||
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
||||
static QPluginLoader pluginLoader(pluginLibName);
|
||||
pluginLoader.setFileName(pluginLibName);
|
||||
// static QPluginLoader pluginLoader(pluginLibName);
|
||||
if (!pluginLoader.load()) {
|
||||
qCritical() << "in directory" << plugInDir.absolutePath();
|
||||
qCritical() << "cannot load plugin" << pluginLoader.fileName();
|
||||
@ -80,6 +83,21 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
||||
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,
|
||||
Worker *worker,
|
||||
QString customerRepository,
|
||||
|
Loading…
Reference in New Issue
Block a user