[SOLVED] qss with special characters
-
Hi,
Something's not clear: is it the content of the style sheet that is problematic or the path to load it ?
-
Strange...
It works fine with Japanese, Chinese, Arabic, Hebrew, Russian and some even quite rare languages like Malayalam BUT something with Dutch/Danish/Portuguese Alphabetical is just not working.
Actually, I've checked
é ë ï ó ö ü å æ é ø...It smells like a bug in Qt.
-
@erez373 said:
Strange...
It works fine with Japanese, Chinese, Arabic, Hebrew, Russian and some even quite rare languages like Malayalam BUT something with Dutch/Danish/Portuguese Alphabetical is just not working.
Actually, I've checked
é ë ï ó ö ü å æ é ø...It smells like a bug in Qt.
What encoding does your QSS file use?
-
@erez373 said:
Strange...
It works fine with Japanese, Chinese, Arabic, Hebrew, Russian and some even quite rare languages like Malayalam BUT something with Dutch/Danish/Portuguese Alphabetical is just not working.
Actually, I've checked
é ë ï ó ö ü å æ é ø...It smells like a bug in Qt.
I am not sure whether the file encoding related.
-
@erez373 said:
I don't think I can set encoding to qss file (like in xml).
Every text file has an encoding. The program which wrote your file used a particular encoding to convert your text into 0s and 1s. You didn't set the encoding, but it is there.
When you read the file, you must use to same encoding that wrote the file.
The easiest way to check that your reader is using the correct encoding, is to read the file into a QString, then write it back out to another file. Does the output file look correct?
Also, how did you convert your QSS file into a QString?
-
@JKSH said:
Does the output file look correct?
The original file and the output file are both ANSII.
If I change the encoding of the original file, read it and save it the encoding of the new one returns to ANSII
(I also see this with Notepad++)-->> ANSII has the special characters defined ... é ë... STRANGE!
@JKSH said:
Also, how did you convert your QSS file into a QString?
I generate a QFile , open it (QIODevice::ReadOnly) and read all the content into a QByteArray.
Next I convert it to QString by generating a QString instance (using QString::QString(const QByteArray & ba)) -
@erez373 said:
The original file and the output file are both ANSII.
...
Next I convert it to QString by generating a QString instance (using QString::QString(const QByteArray & ba))There's your problem. See the documentation:
QString::QString(const QByteArray & ba)
assumes that the QByteArray is encoded in UTF-8.Try
QString::fromLatin1()
instead.-->> ANSII has the special characters defined ... é ë... STRANGE!
Yes, but ANSI and UTF-8 encode 'é' differently from each other.
- ANSI: 'é' = 0xE9
- UTF-8: 'é' = 0xC3A9
-
[SOLVED]
Eventually, the solution is to add escape character '' before any special character which has a unicode between 161 and 255 (including).
E.g. "abékl" -> "ab\ékl"
When looking into Qt source code and specifically to int QCssScanner_Generated::lex() (qcssscanner.cpp) one can find a huge state machine parser (css based) which expects the escape character before unicode characters 161 to 255.
(the parser get called by QWidget::setStyleSheet eventually)The reason Japanese, Chinese and more non-Latin languages worked is because the state machine handles unicode characters from 256 above as is (does not expect the escape).
Hope this will help others.
p.s.
Using QString::fromLatin1() didn't help.