Potential memory leak in QSignalMapper : Qt version 6.3.0
-
Hi, I have the following code, using QSignalMapper:
QSignalMapper* myMapper = new QSignalMapper(this); for(int j=0;j<myList.size(); j++){ connect(myList[j]->timer, SIGNAL(timeout()), myMapper, SLOT(map())); myMapper->setMapping(myList[j]->timer, j); connect(myMapper, SIGNAL(mapped(int)), this, SLOT(up(int))); }
However, this is not working, and giving me the warning:
potential leak of memory pointed to by 'myMapper'
I don't understand why this is not working, and why I am getting the memory leak warning.
I am using Qt version 6.3.0
Thanks
-
Hi,
What exactly is not working ?
As for the warning, you declared myMapper somewhere and never delete it hence the warning. myMapper having a parent means that it will be deleted at some point when the parent is deleted however your tool is likely not aware of that.
-
@SGaist
The up() slot is supposed to show a video in a label. It does not do that with this code.I am using Qt Creator. Is there some way I can fix something to get rid of this warning?
I was wondering if this has got something to do with the Qt version. Since the same code is working properly in Qt version 5.
-
Not knowing what tool you are using I can't answer for the warning.
As for the slot, did you check that it has been called ?
How are you managing that video ? -
@BigBen said in Potential memory leak in QSignalMapper : Qt version 6.3.0:
connect(myMapper, SIGNAL(mapped(int)), this, SLOT(up(int)));
I'm pretty sure that this:
connect(myMapper, SIGNAL(mapped(int)), this, SLOT(up(int)));should not be done in the loop.
There should only be one connect of the mapper to the receiving object