Created
September 9, 2016 18:44
-
-
Save vicatcu/7668fe8f26804e911b1b7fc6ce850a99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class Key, class T> | |
QString mapToString(QMap<Key, T> &map){ | |
// this is derivative of the code that qDebug uses to serialize a QVariantMap | |
// qtbase/src/corelib/io/qdebug.h | |
// template <class Key, class T> | |
// inline QDebug operator<<(QDebug debug, const QMap<Key, T> &map) | |
QByteArray buf; | |
QDataStream s(&buf, QIODevice::ReadWrite); | |
s << "("; | |
for (typename QMap<Key, T>::const_iterator it = map.constBegin(); it != map.constEnd(); ++it) { | |
s << '(' << it.key() << ", " << it.value() << ')'; | |
} | |
s << ')'; | |
return QString::fromLatin1(buf); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
QVariantMap map; | |
map.insert("a", QVariant("123")); | |
map.insert("b", QVariant("234")); | |
qDebug() << mapToString(map); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment