Results 1 to 2 of 2

Thread: Memory leak with QTimer?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Memory leak with QTimer?

    Hi, I have the next code, as far as I've seen, pretty similar to the normal usage of QTimer.

    Qt Code:
    1. QTimer* pAuxTimer = new QTimer();
    2. pAuxTimer->setSingleShot(true);
    3. QSignalMapper* mapper = new QSignalMapper();
    4. connect(pAuxTimer, SIGNAL(timeout()), mapper, SLOT(map()));
    5. connect(mapper, SIGNAL(mapped(QWidget*)), this, SLOT(showTranspAdvertisement(QWidget*)));
    6. mapper->setMapping(pAuxTimer, pAuxWid);
    7. pAuxTimer->start(50);
    To copy to clipboard, switch view to plain text mode 

    It works fine, but it creates a memory leak because that's the end of the function. I can use a non local variable because the code is executed when the user presses a button, so I don't know how many times is gonne be executed, I don't know how many timers I'm gonna have working at the same time...

    Does Qt eliminate them automatically? docs says nothing about that.

    thansk!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Memory leak with QTimer?

    If you provide a parent to the timer through its constructor then Qt will delete the timer once the parent is deleted.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt dll + memory leak
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2009, 13:28
  2. Memory leak of Qt?
    By Sheng in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2009, 23:32
  3. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 16:24
  4. Memory Leak in Qt
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2007, 08:02
  5. Memory leak
    By zlatko in forum Qt Programming
    Replies: 8
    Last Post: 28th March 2006, 19:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.