This works too, with custom datatype:
#include <QtCore>
struct s_{
int val;
};
int main(int argc, char *argv[])
{
s_ s; s.str = "hello"; s.val = 10;
QMap<QByteArray,s_> map;
QHash<QByteArray,s_> hash;
map["string"] = s;
hash["other key"] = s;
qDebug() << map["string"].str << map["string"].val;
qDebug() << hash["other key"].str << hash["other key"].val;
return 0;
}
#include <QtCore>
struct s_{
QString str;
int val;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
s_ s; s.str = "hello"; s.val = 10;
QMap<QByteArray,s_> map;
QHash<QByteArray,s_> hash;
map["string"] = s;
hash["other key"] = s;
qDebug() << map["string"].str << map["string"].val;
qDebug() << hash["other key"].str << hash["other key"].val;
return 0;
}
To copy to clipboard, switch view to plain text mode
What errors do you get ?
Bookmarks