PDA

View Full Version : Plugin destruction



paolom
17th July 2012, 11:50
Hi,

I've a core application that load three different plugins using the QPluginLoader.

On application termination, the QPluginLoader unloads the plugin automatically, but only the third plugin destructor is called (the third cause is the last to be loaded from QPluginLoader).

I need to run some code in each of the plugin before the application termination.

Is it an expected behaviour of the plugin?!

How can I ensure that all the plugin destructor are called during the QPluginLoader unload?!

Many thanks

wysota
17th July 2012, 12:13
Is it an expected behaviour of the plugin?!
No. And I doubt it behaves as you describe it. If an object is destroyed then its destructor is executed unless an exception occurs in a weird place or your program crashes. So either your object is not destroyed or your app gets obliterated by the system.

paolom
17th July 2012, 12:18
The behaviour is exactly that: when I close my application, the only destructor that is called is on the third plugin.
I think that the pluginloader mantains only the reference of the last plugin loaded....or something like that.

The other two plugin are unloaded without destruct it.

Has anybody experience of this?

wysota
17th July 2012, 12:49
The plugin loader can only hold a reference to one instance at a time. If you reuse the same instance of QPluginLoader for many plugins then you are responsible for deleting all the objects yourself.

paolom
17th July 2012, 13:23
Ok,
I've correct my code, but the problem is the same:

To call the destructor of the plugin I need to call the unload() function of the QPluginLoader.

Is it an expected behaviour?

wysota
17th July 2012, 16:08
You mean that if you do:


QObjectList list;
list << loader.instance();

and then:


foreach(QObject *o, list) delete o;
the destructor is not called?

paolom
17th July 2012, 16:18
I've a plugin that handle a thread that do some work.
When the app is closed, I want to be sure that this plugin close all the worker thread.
To do this I want to run some code during the closure of the plugin.
At the start I think to do this on the plugin destructor but I test that without unload() the pluginLoader the plugin destructor is not invoked.
On the Qt examples there is not pluginLoader unload() and when the app is closed no plugin destructor is invoked.

My questions:

As your opinion, has any sense to put any code on the plugin destructor, or I need to call another plugin method to do this operation before the plugin is closed??

Does I need to call the unload() function of the pluginLoader?

Which is the safe mode to delete the plugin instances?

Many thanks :)

wysota
17th July 2012, 16:32
When the app is closed, I want to be sure that this plugin close all the worker thread.
To do this I want to run some code during the closure of the plugin.
You shouldn't do that using a destructor but rather a dedicated close() method that each plugin implements and that your plugin handling infrastructure calls before closing the whole system.