سؤال

I have a QString with content that looks something like this:

"resolution=[imagesize]&quality=[imagequal]".

And I have a QHash<QString, QString> mDefaults container that holds a list with some of my 'key' values. ("imagesize" and "imagequal" are so called 'keys' that I need to replace with values from my hash container)

mDefaults.insert("imagesize", "320x240");
mDefaults.insert("imagequal", "standard");

My goal is to get a string that will look something like this: "resolution=320x240&quality=standard" (Note that "[" and "]" are gone too)

Is there any fast/good way to do this kind of string key-value replacement with Qt library?

Thanks.

هل كانت مفيدة؟

المحلول

for(QMap::iterator i=mDefaults.begin();i!=mDefaults.end();++i) {
    myString.replace(QString("[%1]").arg(i.key()), i.value());
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top