Results 1 to 3 of 3

Thread: QEvent memory management

  1. #1
    Join Date
    Aug 2010
    Location
    Finland
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QEvent memory management

    I have a question, who is responsible for deletion of QEvent objects? For example, in the code below I create a new QEvent object and pass it further to parent:

    Qt Code:
    1. void IxGwText::keyPressEvent(QKeyEvent *event)
    2. {
    3. QString text = event->text();
    4.  
    5. QKeyEvent *newEvent;
    6.  
    7. if(text != "")
    8. {
    9. text = text.toLower();
    10. newEvent = new QKeyEvent(event->type(), event->key(), event->modifiers(), text);
    11. QGraphicsTextItem::keyPressEvent(newEvent);
    12. }
    13. else
    14. {
    15. QGraphicsTextItem::keyPressEvent(event);
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    newEvent is a newly created event. Is there a memory leak? Who handles the event object deletion? Thanx!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QEvent memory management

    When you do not use postEvent, yes, there's a memory leak as your event is not deleted.

    Create the event on the stack instead.

  3. The following user says thank you to tbscope for this useful post:

    staser12 (24th August 2010)

  4. #3
    Join Date
    Aug 2010
    Location
    Finland
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QEvent memory management

    Thanx for your answer. I'll try it.

Similar Threads

  1. QStackedWidget and memory management
    By martinn in forum Newbie
    Replies: 14
    Last Post: 8th April 2010, 00:14
  2. Memory Management Reg
    By BalaQT in forum Newbie
    Replies: 10
    Last Post: 4th February 2010, 12:43
  3. Memory management
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:48
  4. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  5. Memory management in QT
    By Gayathri in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2006, 07:21

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.