1

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();
4

1 回答 1

1

从文档中:

QPluginLoader::instance

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

QPluginLoader::卸载

不要试图删除根组件。相反,依靠 unload() 会在需要时自动删除它。

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

于 2012-05-13T13:11:03.583 回答