Certainly this is also quite simple to implement, but I was hoping that there is a more elegant solution.
I think the only other way is to create feature request for QtGui, or implement a Qt patch yourself - to add a QBrush::toString() method (or QTextStream overload), with a corresponding QBrush::fromString().
Another solution: Store all your data as key-value pairs in QMap<QString, QVariant> and write it to QDataStream. Next, applications will read full QMap contents from stream, then access needed values by their names.
Unfortunately, when I try to save a QList<MyStruct>, I get the following error at runtime:
QVariant::save: unable to save type 'QList<Action>' (type id: 1032).
ASSERT failure in QVariant::save: "Invalid type to save", file kernel\qvariant.cpp, line 2124
Invalid parameter passed to C runtime function.
This is even though I have (after some wrestling) managed to successfully save a Action (MyStruct) using QVariant::fromValue(), having registered both Action as a metatype as well as its operators in main():
When you deploy,
there might be more reads for full json string.
The code you shown, will try to parse on each read. Make sure the code can
handle that it comes in blocks and not bail out if parse fails.
I couldn't quite believe that this could be an actual bug, so I kept testing.
And the result... oh well... I'm truly ashamed... I have included QDataStream in every file... except the one I actually tested.
So the solution is: #include <QDataStream> Facepalm
Thanks for your tips, I'm now gonna implement what you told me.
Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.