It depends what techniques you use in your program (for example the MVC pattern has its own support for D&D).
In most basic approach you need to use QMimeData to carry the data for you and dropEvent to handle the drop itself.
It depends what techniques you use in your program (for example the MVC pattern has its own support for D&D).
In most basic approach you need to use QMimeData to carry the data for you and dropEvent to handle the drop itself.
Ah I fixed this, in a messy way but still fixed it.
I just cast the pointer into an int and stored that as mimedata. Then cast it back on the other side. Worked as the objects are on the heap. Still used messy casting.
That's not very elegant
You may try:
*) - you have to provide this operator yourself, for example using a QDataStream or something like thatQt Code:
QByteArray myData; myData = myStructObj.serialize(); // * mimeData->setData("application/x-mystruct", myData);To copy to clipboard, switch view to plain text mode
For simple structures using a TSV or CSV is a nice way to go too. If you don't plan to drag the item out of your application, you can stick with pointers too. Just dragging your "int" to some text editor or something like that may provide weird results![]()
Ah it's just got to stay in the same application, so working out how to serialize the entire Tree structure seemed a bit overkill when it was on the heap. Reuse just isn't an issue.
EDIT: It's for a uni project, so getting it working is the bigger issue at the moment ¬_¬
can you give a small hint how to do that? QDataStream doesn't have that big selection of functions to get your Objects in there. Can you store any data from a pointer in a DataStream?Originally Posted by wysota
Not from a pointer. Reimplement the operator for the object itself and for the pointer.
yeah, but how do i have to implement that operator? Do I need to build something similar to a string out of the objects attributes? And how do I get the real Object back at the point where the user ended the drag'n'drop operation?Originally Posted by wysota
It doesn't matter how you implement it. It only matters that it has to be converted to a stream of bytes and then the conversion has to be reversed (by implementing deserialisation from the data stream).Originally Posted by kiker99
For example you could store an xml representation of your object in the stream (although it would be an overkill).
kiker99 (16th May 2006)
ok, thanks a lot![]()
so you passed a string containing the text representation of the int value of the pointer into setData? hilarious![]()
Software Engineer
Bookmarks