Results 1 to 6 of 6

Thread: How to use QMimeData to pass a list of pointers

  1. #1
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QMimeData to pass a list of pointers

    I'm try use to use QMimeData to pass a list of pointers of a custom defined class, such like
    Qt Code:
    1. QList<MyClass *>
    To copy to clipboard, switch view to plain text mode 
    in drag and drop.

    I think I shuold use the setData() funtion of QMimeData, but I have no idea how to put the list into it.

    Thanks in advance.

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

    Default Re: How to use QMimeData to pass a list of pointers

    Serialize pointers into a byte array and pass that into QMimeData. However usually it would be better to serialize the data behind the pointers instead.
    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.


  3. #3
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QMimeData to pass a list of pointers

    Could you give me an example of serializing pointers into QByteArray?

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

    Default Re: How to use QMimeData to pass a list of pointers

    Convert them into integers and store in the array directly or using QDataStream.
    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.


  5. The following user says thank you to wysota for this useful post:

    Seishin (2nd May 2013)

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to use QMimeData to pass a list of pointers

    You might find quintptr useful for the static cast.

  7. The following user says thank you to ChrisW67 for this useful post:

    Seishin (2nd May 2013)

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use QMimeData to pass a list of pointers

    Even if it is possible to do that (seralizing pointers into a text representation) I suggest you stay away from it as far as possible (as in: don't do it at all).
    This is an extremly bad hack, requires reinterpret_cast, has no runtime safety at all, and so on.

    If you need access to the same list in multiple locations in your program, do it in a way that is independent of drag&drop. E.g. as a member in an object that both locations have access to, or in a singleton, etc.

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 30th November 2012, 03:58
  2. Replies: 5
    Last Post: 30th July 2012, 20:07
  3. Replies: 3
    Last Post: 6th April 2012, 16:44
  4. problem with a list of pointers
    By maider in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2009, 12:45
  5. Is there a known problem with QMimeData on Mac OS X?
    By Wurgl in forum Qt Programming
    Replies: 8
    Last Post: 27th February 2008, 22:21

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.