Reputation: 604
I'm trying to loop through a QHash using foreach and get each pair in the QHash and then get the keys and values of those so I can append them to a string.
Here's what I have
QString Packet::Serialize() {
QString sBuilder = Command.toUpper() + " ";
foreach(QMap<QString,QString> pair, Attributes) {
sBuilder.append(pair); // i know this isn't right because I couldn't
// finish the statement
}
}
The variable Attributes
is the QHash.
Also, I realize the code is probably 100% wrong because I'm converting it from C#.
Upvotes: 1
Views: 7808
Reputation: 17535
Looks like you're trying to append each key/value pair to a string? Something like this would work:
QStringList data;
foreach(const QString &key, Attributes.keys())
data << key << Attributes.value(key);
sBuilder += data.join(" ");
Upvotes: 2