开发者

QSA's children objects deletion problem

I've some problems with deleting QSA's referred objects. In constructor, I've wrote:

  QSProject * project = {initialization of QSProject}
  MyWrapper * wrapper = new MyWrapper; // MyWrapper is QObject's child. It comes without parent here
  project->addObject(wrapper);

I've wrote in descructor:

  project->cle开发者_如何学编程arObjects();
  delete project;
  delete wrapper;

This code cause to segfault at destructor's execution, exactly -- when I'm trying to delete wrapper.

I've made some research and I know that:

  1. QSProject doesn't delete his "children objects", so this is not a "double delete" problem
  2. If I don't add wrapper to QSProject in constructor, it works well.
  3. If I don't delete wrapper in descructor, it works well (but memory leaks).

What's up?


First, I'm not familiar with QSA, but given how the Qt API usually works QSProject is likely taking ownership of the object. This means QSProject is reparenting the object using QObject::setParent().

In which case you are doubly deleting the object.

Have you verified with a tool such as valgrind that you are in fact leaking memory when you omit the delete?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜