Results 1 to 2 of 2

Thread: QDrag ownership

  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 16:24.

  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: QDrag ownership

    I think Qt takes the ownership. You can easily verify it by subclassing QDrag and putting a qDebug() statement in the destructor to see if and when it is invoked.
    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. Ownership in a QWidget
    By tuli in forum Newbie
    Replies: 5
    Last Post: 23rd March 2015, 09:57
  2. QComboBox setModel - ownership???
    By lotek in forum Newbie
    Replies: 3
    Last Post: 5th August 2011, 16:37
  3. QTableView and QStyledItemDelegate ownership
    By lxman in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2011, 06:19
  4. Replies: 3
    Last Post: 15th May 2010, 00:00
  5. Thread Ownership Problem
    By tntcoda in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 01: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.