关于VTK+QT在关闭程序后进程无法结束的问题

来源:互联网 发布:java 命令打包成jar包 编辑:程序博客网 时间:2024/05/22 00:35

之前解决了qt+vtk+ikt显示dicom图像的问题,在写程序的时候发现了另外一个比较致命的大问题,即结束程序的时候,主进程无法退出,只是窗口关闭,测试了好久,发现关闭窗口之后无法跳进析构函数或者自己写的关闭函数中,只是单单关闭了窗口。

后来我对qt窗口的关闭按钮事件进行拦截,方法是从http://sunshine1106.blog.51cto.com/1371108/305106/ 作者的总结中学习参考得出,但是即使执行qApp->exit(0),或者qApp->quit()或者qApp->closeAllwindows()等函数仍无法结束主程序进程。

然后我在开头定义setAttribute(Qt::WA_DeleteOnClose, true);也无法达到目的。

后来我试着删除自己定义的vtkSmartPoint的vtkimageview2的对象,使用的是调用它自己的删除函数fastdelete(),运行之后发现进程被删除了。

虽然目的达到了,但是还是觉得奇怪,之前网上的介绍都说vtk的smartpoint类是能够自动根据程序进行指针删除,内存资源释放的,不知道为什么在我的程序里他无法自动释放。

关于smartpoint类中delete和fastdelete函数的说明如下:

<span style="font-size:14px;">  // Description:  // Delete a VTK object.  This method should always be used to delete  // an object when the New() method was used to create it. Using the  // C++ delete method will not work with reference counting.  virtual void Delete();  // Description:  // Delete a reference to this object.  This version will not invoke  // garbage collection and can potentially leak the object if it is  // part of a reference loop.  Use this method only when it is known  // that the object has another reference and would not be collected  // if a full garbage collection check were done.  virtual void FastDelete();</span>



0 0
原创粉丝点击