How to control the deletion of an object that has been transmitted through a signal slot?

I just added webcam support to my application using the video integration library and OpenCV.

The video stream is located in QThread (manufacturer) and emits a signal sending QImage * for my application to update the graphic element it needs.

The memory management side is that I delete QImage * in the consumer slot as soon as the slot finishes using it. The problem is that I would like more than one object to accept QImage * data.

In this case, I now need to track all the consumers (with reference counting) of the data, and then delete QImage * (most likely in the producer thread) when they are all finished?

+3
source share
1 answer

Using smart pointers should do most of the work for you: QSharedPointer

+8
source

Source: https://habr.com/ru/post/1789971/


All Articles