PDA

View Full Version : Plugin ctor executes, but not dtor ?



scollyer
12th January 2008, 13:59
[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 (QLibrary::isLibrary(file_name))
{
QPluginLoader loader(plugin_dir.absoluteFilePath(file_name));

if (TransferrerInterface *interface = qobject_cast<TransferrerInterface*>(loader.instance()) )
{

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 ?

wysota
12th January 2008, 14:18
What exactly do you mean by "plugin destructor"? Destructor of a class created by some factory function from within a plugin or destructor of the object returned by QPluginLoader::instance()? Did you call delete on the returned pointer?