There are all kinds of fishy things. For example who frees className or why does the operator ignore the passed in item?
My recommendation would be to separate serialization from the item.
For example like this
{
public:
QVariantMap serialize() const;
static MyItem* deserizalize(const QVariantMap &data);
}
class MyItem : public QGraphicsItem
{
public:
QVariantMap serialize() const;
static MyItem* deserizalize(const QVariantMap &data);
}
To copy to clipboard, switch view to plain text mode
Used like this
foreach (MyItem* item, items) {
stream << item->serialize();
}
QDataStream stream(...);
foreach (MyItem* item, items) {
stream << item->serialize();
}
To copy to clipboard, switch view to plain text mode
while (!stream.atEnd()) {
QVariantMap data;
stream >> data;
items << MyItem::deserialize(data);
}
QDataStream stream(...);
while (!stream.atEnd()) {
QVariantMap data;
stream >> data;
items << MyItem::deserialize(data);
}
To copy to clipboard, switch view to plain text mode
For the classname I would suggest to either use QByteArray or to have an entry for that in the QVariantMap (but also a QByteArray to avoid manual memory management)
Cheers,
_
Bookmarks