Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Potential memory leak in QSignalMapper : Qt version 6.3.0

Potential memory leak in QSignalMapper : Qt version 6.3.0

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsignalmapperqt6.3.0memory leak
5 Posts 3 Posters 778 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BigBen
    wrote on last edited by BigBen
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • B Offline
        B Offline
        BigBen
        wrote on last edited by BigBen
        #3

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • mranger90M Offline
            mranger90M Offline
            mranger90
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved