Fix reloading of plugins
Unloading and reloading a plugin didn't work correctly, because we didn't reset instance to 0 on unload. Task-number: QTBUG-26098 Change-Id: Ic3e4497f359b1ca455be949dce9cafa9d67d8039 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3e3790b2c7
commit
47c48ea87a
@ -429,6 +429,7 @@ bool QLibraryPrivate::unload()
|
|||||||
libraryRefCount.deref();
|
libraryRefCount.deref();
|
||||||
}
|
}
|
||||||
pHnd = 0;
|
pHnd = 0;
|
||||||
|
instance = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ private slots:
|
|||||||
void loadDebugObj();
|
void loadDebugObj();
|
||||||
void loadCorruptElf();
|
void loadCorruptElf();
|
||||||
void loadGarbage();
|
void loadGarbage();
|
||||||
|
void reloadPlugin();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QPluginLoader::errorString()
|
void tst_QPluginLoader::errorString()
|
||||||
@ -291,5 +292,28 @@ void tst_QPluginLoader::loadGarbage()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QPluginLoader::reloadPlugin()
|
||||||
|
{
|
||||||
|
QPluginLoader loader;
|
||||||
|
loader.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin
|
||||||
|
loader.load(); // not recommended, instance() should do the job.
|
||||||
|
PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance());
|
||||||
|
QVERIFY(instance);
|
||||||
|
QCOMPARE(instance->pluginName(), QLatin1String("Plugin ok"));
|
||||||
|
|
||||||
|
QSignalSpy spy(loader.instance(), SIGNAL(destroyed()));
|
||||||
|
QVERIFY(spy.isValid());
|
||||||
|
QVERIFY(loader.unload()); // refcount reached 0, did really unload
|
||||||
|
QCOMPARE(spy.count(), 1);
|
||||||
|
|
||||||
|
// reload plugin
|
||||||
|
QVERIFY(loader.load());
|
||||||
|
QVERIFY(loader.isLoaded());
|
||||||
|
|
||||||
|
PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader.instance());
|
||||||
|
QVERIFY(instance2);
|
||||||
|
QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QPluginLoader)
|
QTEST_MAIN(tst_QPluginLoader)
|
||||||
#include "tst_qpluginloader.moc"
|
#include "tst_qpluginloader.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user