Results 1 to 2 of 2

Thread: Plugin ctor executes, but not dtor ?

  1. #1
    Join Date
    Jan 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Plugin ctor executes, but not dtor ?

    [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:

    Qt Code:
    1. foreach (QString file_name, plugin_dir.entryList(QDir::Files))
    2. {
    3. if (QLibrary::isLibrary(file_name))
    4. {
    5. QPluginLoader loader(plugin_dir.absoluteFilePath(file_name));
    6.  
    7. if (TransferrerInterface *interface = qobject_cast<TransferrerInterface*>(loader.instance()) )
    8. {
    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 ?
    Last edited by jpn; 16th January 2008 at 11:43. Reason: missing [code] tags

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

    Default Re: Plugin ctor executes, but not dtor ?

    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?

Similar Threads

  1. Need help making plugin
    By vieraci in forum Qt Programming
    Replies: 10
    Last Post: 24th September 2007, 13:20
  2. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  3. plugin loading problem
    By naresh in forum Qt Programming
    Replies: 6
    Last Post: 9th June 2007, 19:05
  4. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 09:01

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.