[This is a dup of a posting on the qt-interest mailing list -
apologies to those who've seen it before]
have a plugin instance that I create using QPluginLoader::instance()
and that I (currently) allow to be unloaded by dropping off the end
of the program i.e. I don't explicitly call QPluginLoader::unload()
and rely on the the fact that this should happen automatically.
It seems that QPluginLoader::instance() causes the plugin's
ctor to execute, but that plugin's dtor never runs.
I'm loading a set of plugins with code like this:
foreach
(QString file_name, plugin_dir.
entryList(QDir::Files)) {
{
if (TransferrerInterface *interface = qobject_cast<TransferrerInterface*>(loader.instance()) )
{
foreach (QString file_name, plugin_dir.entryList(QDir::Files))
{
if (QLibrary::isLibrary(file_name))
{
QPluginLoader loader(plugin_dir.absoluteFilePath(file_name));
if (TransferrerInterface *interface = qobject_cast<TransferrerInterface*>(loader.instance()) )
{
To copy to clipboard, switch view to plain text mode
which is based on code in the Blanchette/Summerfied book.
Now, having looked at the docs for QPluginLoader, I'm beginning
to wonder if this code is dubious, since the QPluginLoader
in question goes out of scope long before it gets a chance
to call unload() (and I, of course, can't manually call unload()
for the same reason).
So the questions are:
1. Is the code above strictly incorrect ?
2. As a corollary, should all QPluginLoader objects have the
same lifetime as the instances which they create, in order to
allow unload() to be called ?
3. Is the code above the reason that the plugin dtor is not called ?
Bookmarks