How does the "toString" method of qt data structures work?
-
I found myself trying to save the textual representation of a QVariantMap (QMap<QString, QVariantMap>> actually) like as if I were to write
qDebug() << myMap
which yields the correct text data put to the console, but instead have the result in a file. I tried with QDataStream class but it can only handle binary form, I managed to do it finally like this:
QDebug outDebug(&file);
outDebug << myMap;
But it really bothers me that I have no idea what is going on behind the scenes. I assume eitherQDebug & QDebug::operator<<(const QByteArray & b)
orQDebug & QDebug::operator<<(const QString & s)
functions are called after an implicit conversion, but how does that implicit conversion work?Also I have a custom (non-QObject)! class that is among the stored QVariants and it's textual repesentation is an empty string. Is there a way to customize that?
-
YourClass
{
friend QDataStream & operator << (QDataStream & out, const YourClass& t)
{
out << t._nom;
return out;
}
};