QThread is creating a memory leak

前端 未结 2 1042
我寻月下人不归
我寻月下人不归 2021-01-27 07:36

After much testing and changes to my QT application, Visual Leak Detector identified the source of a pesky leak (8 bytes). VLD reported the QT application is clean except for a

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 08:18

    Answers:

    • Why is QThread* not destroying itself when the worker thread completed its work?

    Because there are different ways to use QThread in which at least one must be able to query thread states or class members after worker has finished. Also the thread may be restarted.

    • How can I force the QThread* to delete the thread and worker object when work is complete?

    The finished signal should be enough for you to call a slot deleting both.

    • Should QThread be implemented differently?

    There are different implementations for different situations. http://qt-project.org/doc/qt-5.0/qtcore/thread-basics.html

提交回复
热议问题