View Full Version : How to use QMimeData to pass a list of pointers

1st May 2013, 22:08
I'm try use to use QMimeData to pass a list of pointers of a custom defined class, such like
QList<MyClass *> 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.

1st May 2013, 23:39
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.

1st May 2013, 23:59
Could you give me an example of serializing pointers into QByteArray?

2nd May 2013, 02:15
Convert them into integers and store in the array directly or using QDataStream.

2nd May 2013, 02:21
You might find quintptr useful for the static cast.

3rd May 2013, 23:14
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.