Results 1 to 8 of 8

Thread: Plugin destruction

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default Plugin destruction

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin destruction

    Quote Originally Posted by paolom View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Plugin destruction

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin destruction

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Plugin destruction

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin destruction

    You mean that if you do:

    Qt Code:
    1. QObjectList list;
    2. list << loader.instance();
    To copy to clipboard, switch view to plain text mode 

    and then:

    Qt Code:
    1. foreach(QObject *o, list) delete o;
    To copy to clipboard, switch view to plain text mode 
    the destructor is not called?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Plugin destruction

    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

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin destruction

    Quote Originally Posted by paolom View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How QDeclarativeView destruction
    By xman_ss in forum Qt Programming
    Replies: 3
    Last Post: 27th April 2012, 07:55
  2. Destruction in separate threads
    By KevinKnowles in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2012, 09:49
  3. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  4. What happens after closing and before destruction?
    By Raccoon29 in forum Qt Programming
    Replies: 45
    Last Post: 20th May 2008, 09:33
  5. processEvents preventing class from destruction?
    By bowser in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 4th January 2008, 17:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.