PDA

View Full Version : strange behavious with QMap and non Latin characters



brixton
16th November 2010, 06:33
I have the following code (map is a QVariantMap):

void XmlHandler::addToMap(QString key, QVariant value)
{
qDebug() << "key:" << key << " value:" << value;

qDebug() << "before: " << map;
map.insert(key, value);

qDebug() << "after: " << map << endl;
}


Which produces the following output:

key: "a" value: QVariant(QString, "ab")
before: QMap()
after: QMap(("a", QVariant(QString, "ab") ) )

key: "b" value: QVariant(QString, "ab")
before: QMap(("a", QVariant(QString, "ab") ) )
after: QMap(("a", QVariant(QString, "ab") ) ( "b" , QVariant(QString, "ab") ) )

However... When I use Arabic input, the QMap is courrupted:

key: "ا" value: QVariant(QString, "او")
before: QMap()
after: QMap(("ا", QVariant(QString, "او") ) )

key: "و" value: QVariant(QString, "او")
before: QMap(("ا", QVariant(QString, "او") ) )
after: QMap(("ا", QVariant(QString, "او") ) ( "و" , QVariant(QString, "او") ) )

You can see that the keys and values have been mixed after the second insert!

I assumed I was making a mistake somewhere, but I sure don't see one. Can someone suggest what might be going wrong?

Thanks, B

wysota
16th November 2010, 07:32
Please provide a minimal compilable example reproducing the problem.

brixton
16th November 2010, 08:16
I've solved the "problem". It is actually just the representation in Qt of right-to-left alphabets when there are "(" and ")" characters. It appears to be corrupt data but this is only the way that Qt is displaying the text.

QMap(("ا", QVariant(QString, "او") ) ( "و" , QVariant(QString, "او") ) )
actually is:

QMap(("ا", QVariant(QString, "او") ))
QMap(("و", QVariant(QString, "او") )) (if you put in a line break)

brixton
18th November 2010, 07:43
It is just unlucky that QMap's output exactly reverses Arabic text to look like the elements have been corrupted internally!

Is there a way of marking threads as solved?