Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] qss with special characters
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] qss with special characters

Scheduled Pinned Locked Moved General and Desktop
special charactqss
11 Posts 4 Posters 6.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Something's not clear: is it the content of the style sheet that is problematic or the path to load it ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • E Offline
      E Offline
      erez373
      wrote on last edited by
      #3

      Well, in my qss file(s), some attributes have a path with special characters.
      For example: the bacground image url of a button is c:\users<name with special characters>\images

      1 Reply Last reply
      0
      • E Offline
        E Offline
        erez373
        wrote on last edited by
        #4

        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.

        JKSHJ C 2 Replies Last reply
        0
        • E erez373

          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.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #5

          @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?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          E 1 Reply Last reply
          0
          • E erez373

            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.

            C Offline
            C Offline
            Cary Tian
            wrote on last edited by
            #6

            @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.

            1 Reply Last reply
            0
            • JKSHJ JKSH

              @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?

              E Offline
              E Offline
              erez373
              wrote on last edited by
              #7

              @JKSH

              I don't think I can set encoding to qss file (like in xml).
              Nevertheless, I thought the encoding is utf-8 otherwise how Malayalam worked fine ?

              JKSHJ 1 Reply Last reply
              0
              • E erez373

                @JKSH

                I don't think I can set encoding to qss file (like in xml).
                Nevertheless, I thought the encoding is utf-8 otherwise how Malayalam worked fine ?

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by JKSH
                #8

                @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?

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                E 1 Reply Last reply
                0
                • JKSHJ JKSH

                  @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?

                  E Offline
                  E Offline
                  erez373
                  wrote on last edited by
                  #9

                  @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))

                  JKSHJ 1 Reply Last reply
                  0
                  • E erez373

                    @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))

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by JKSH
                    #10

                    @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

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      erez373
                      wrote on last edited by erez373
                      #11

                      [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.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved