I'm trying to understand how data gets passed around when using drag and drop in Qt. From what I understood from the examples I've been studying, you first define a widget as draggable by overriding methods inherited through QWidget.
In the implementation of the overridden method, the examples I've been looking at instantiate a pointer to a QMimeData object, and store information in it by calling setText(QString object) and setData(QByteArray object). They store information in the QByteArray object with the "<<" operator:
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << labelText << QPoint(ev->pos() - rect().topLeft());
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/x-fridgemagnet", itemData);
mimeData->setText(labelText);
On the definition of the dropEvent() method in the widget that accepts the drops, both of those variables were retrieved with the ">>" operator:
QString text;
QPoint offset;
dataStream >> text >> offset;
In the setData() method, application/x-fridgemagnet was passed as a MIME type argument. Was that defined somewhere else or its just something you can make up?
How can I store and retrieve a custom object inside the QMimeData object? I tried this:
dataStream << labelText << QPoint(ev->pos() - rect().topLeft()) << myObject;
and tried to retrieve it like this:
myClass myObject;
dataStream >> text >> offset >> myObject;
But it didn't work, says theres "no match for 'operator >>'". Any tips on what should I do?