删除Qt中的插件崩溃

时间:2012-05-13 12:47:45

标签: qt qt4

我使用plotter = qobject_cast<PlotterInterface*>(plugin);初始化插件当我关闭应用程序时,在closeEvent(QCloseEvent *event)我尝试使用delete plotter;删除插件但是我崩溃了。如果我没错,可以删除用new创建的对象。为什么我会遇到这个崩溃?

编辑(插件导入):

QPluginLoader* pluginLoader = new QPluginLoader(pluginDir.absoluteFilePath(fileName)); 
QObject* plugin = pluginLoader->instance(); 
plotter = qobject_cast<PlotterInterface*>(plugin); 
plotter->initPlotter();

1 个答案:

答案 0 :(得分:1)

来自文档:

QPluginLoader::instance

  

...当QPluginLoader被销毁时,不会删除此函数返回的根组件。如果要确保删除根组件,则应在不再需要访问核心组件时立即调用unload()...

QPluginLoader::unload

  

不要尝试删除根组件。而是依赖于unload()会在需要时自动删除它。

尝试使用卸载并查看问题是否仍然存在。

相关问题