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:
Lars Knoll 2012-07-30 12:30:58 +02:00 committed by Qt by Nokia
parent 3e3790b2c7
commit 47c48ea87a
2 changed files with 25 additions and 0 deletions

View File

@ -429,6 +429,7 @@ bool QLibraryPrivate::unload()
libraryRefCount.deref();
}
pHnd = 0;
instance = 0;
}
}

View File

@ -109,6 +109,7 @@ private slots:
void loadDebugObj();
void loadCorruptElf();
void loadGarbage();
void reloadPlugin();
};
void tst_QPluginLoader::errorString()
@ -291,5 +292,28 @@ void tst_QPluginLoader::loadGarbage()
#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)
#include "tst_qpluginloader.moc"