Results 1 to 3 of 3

Thread: QThread and heap

  1. #1
    Join Date
    Mar 2006
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QThread and heap

    Hi.I've a question.
    In my application I use a QThread to do some tasks and the thread allocates some object in the heap with new.
    When i delete the thread does the objects allocated by this thread delete themself or i've to explicitly delete these objects in the thread decostructor to avoid that these objects remain in the memory till the termination of the application?

    Sorry for my english

    Thank you!!

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

    Default Re: QThread and heap

    I assume you didn't set QThread as parent of your custom objects. So the answer is -- yes, you have to delete them explicitely. You can use QThreadStorage to ease your task a little.

  3. #3
    Join Date
    Mar 2006
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread and heap

    Ok.Thanks.You know,the problem was that in that thread I do a download by mean of a QHttp object.

    When i want to stop it i cannot do session->abort() o delete session because the application crashes so i was looking for a way to delete session (the QHttp object) and then the thread without get a crash.
    It seems to work fine if in the thread decostructor i do session->deleteLater() but i have to call thread->wait before delete thread.


Similar Threads

  1. QThread + QTimer + skype4Com throws exception
    By sadjoker in forum Newbie
    Replies: 1
    Last Post: 22nd December 2008, 15:24

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.