首页 > 解决方案 > How to free an object after all slots were executed in Qt?

问题描述

I am facing an issue with Qt's signal and slot concept, as it is working asynchronously. I'm currently passing a pointer to an object which is created right before emitting a signal. I need to do this, because all receiving slots should use this object and be able to use the same state. I'm now running into problems, because I can't find a way to free the object after all the connected slots were executed. Is there an option for this?

标签: c++qt

解决方案


您可以使用QSharedPointer. 当没有人再引用它时,它将自动销毁它所持有的对象。


推荐阅读