Hi!

I feel the need to drag and drop a pointer to an object (application internally only), but my skills are too weak to accomplish this.

I figure the way to do it is to construct a QByteArray from a pointer to MyObject and put it into a QMimeData object.

Drag:
Qt Code:
  1. MyObject *myobject = new MyObject();
  2.  
  3. QMimeData *mimeData = new QMimeData;
  4. mimeData->setData("myobject/pointer", QByteArray( (char*)&myobject, sizeof(myobject) ));
To copy to clipboard, switch view to plain text mode 

This code takes the address of the myobject pointer and converts it to a char pointer. That char pointer is passed as argument to the QByteArray constructor along with the right size, so that the QByteArray should contain the bytes of the address of my object. Right?

Now the unwrapping in the drop:

Qt Code:
  1. MyObject* p;
  2. char* data = event->mimeData()->data("myobject/pointer").data();
  3. p = (MyObject*)(*data);
  4. qDebug() << p;
  5. /* BOOM */
To copy to clipboard, switch view to plain text mode 

mimeData()->data() returns a QByteArray.
QByteArray.data() returns a char* to the data.
So I hoped to take the contents of the data with *data and cast it to a pointer to MyObject, but it crashes.

Little help please?