Results 1 to 2 of 2

Thread: QDrag ownership

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QDrag ownership

    I implemented some custom drag+drop in the standard way. Part of the dragging code:

    Qt Code:
    1. QDrag* drag = new QDrag(this);
    2. drag->exec();
    3. ...
    To copy to clipboard, switch view to plain text mode 

    Now I am wondering: Who owns the QDrag* object 'drag'?

    It seems to me that I do, and I have to do delete the drag object before returning:

    Qt Code:
    1. QDrag* drag = new QDrag(this);
    2. drag->exec();
    3. ...
    4. delete drag;
    5. ...
    To copy to clipboard, switch view to plain text mode 

    However, in none of the Qt drag+drop examples this is done. They just let the pointer go out of scope and dont bother about it!

    (note that the 'this' passed to the constructor is not a 'QObject* parent' but the source of the dragging.)


    https://doc.qt.io/qt-5/qtwidgets-dra...idget-cpp.html


    The documentation doesnt say anything special either.


    Who owns it? Do I have to delete it or not?
    Last edited by tuli; 19th July 2018 at 15:24.

Similar Threads

  1. Ownership in a QWidget
    By tuli in forum Newbie
    Replies: 5
    Last Post: 23rd March 2015, 08:57
  2. QComboBox setModel - ownership???
    By lotek in forum Newbie
    Replies: 3
    Last Post: 5th August 2011, 15:37
  3. QTableView and QStyledItemDelegate ownership
    By lxman in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2011, 05:19
  4. Replies: 3
    Last Post: 14th May 2010, 23:00
  5. Thread Ownership Problem
    By tntcoda in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 00:18

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