Results 1 to 2 of 2

Thread: QDrag ownership

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    247
    Thanks
    29
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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, 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
  •  
Qt is a trademark of The Qt Company.