Results 1 to 2 of 2

Thread: Who deletes the Worker object moved to a QThread?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Who deletes the Worker object moved to a QThread?

    I can't find anything definitive either. The best I can suggest is to put a breakpoint in the Worker Object's destructor and see if it hits, then examine the call stack to find out who is deleting it.

    I guess part of my confusion is the difference between being the owner and being the parent -- which I thought were synonymous in Qt.
    Well, not exactly. Being an owner means you control the lifetime of the C++ object instances you own, so you determine when they go out of scope and get deleted. If you are owned, you may not be able to find out who your owner is. Being parented is a more formal, hierarchical arrangement, eg. in Qt you can call QObject::parent() and get a pointer to your parent QObject (who is also your owner).

    An example: QTableWidgetItem instances are owned by the QTableWidget they are set on, but they are not parented by the QTableWidget. On the other hand, if you call QTableWidget::setCellWidget(), the QWidget pointer you pass in becomes both owned and parented by the QTableWidget.
    Last edited by d_stranz; 2nd May 2017 at 23:06.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    SpiceWeasel (3rd May 2017)

Similar Threads

  1. QThread and New Object Creation
    By pratham_shah in forum Qt Programming
    Replies: 6
    Last Post: 26th April 2013, 11:11
  2. Replies: 6
    Last Post: 23rd March 2013, 21:50
  3. Replies: 15
    Last Post: 4th August 2012, 19:11
  4. Multiple start() on same QThread Object
    By mdecandia in forum Qt Programming
    Replies: 4
    Last Post: 3rd November 2009, 08:14
  5. strange ailment "Object moved to here"
    By s410i in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2008, 23:27

Tags for this Thread

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.