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
QtWS25 Last Chance

[SOLVED] qss with special characters

Scheduled Pinned Locked Moved General and Desktop
special charactqss
11 Posts 4 Posters 5.9k Views
  • 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.
  • E Offline
    E Offline
    erez373
    wrote on 14 Jun 2015, 14:32 last edited by erez373
    #1

    HI,

    I have a qss file with a special character e.g. 'é'
    Special characters can appear in my code as I depend on the "My Documents" path in Windows.
    The qss is loaded to a QString.

    The problem is with 'QWidget::setStyleSheet' - it does not know how to handle the special characters and as a result my style is not loaded.
    So far I couldn't find any answer and I hope it is not a bug with Qt platform.

    Any ideas how to solve this ?
    What will happen if for example the user's account name is in Japanese ? Qt is not capable of handling it ?

    Thanks

    [SOLVED] - See below

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Jun 2015, 20:25 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 14 Jun 2015, 20:34 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 15 Jun 2015, 07:33 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.

          J C 2 Replies Last reply 15 Jun 2015, 07:55
          0
          • E erez373
            15 Jun 2015, 07:33

            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.

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 15 Jun 2015, 07:55 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 15 Jun 2015, 08:15
            0
            • E erez373
              15 Jun 2015, 07:33

              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 15 Jun 2015, 07:58 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
              • J JKSH
                15 Jun 2015, 07:55

                @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 15 Jun 2015, 08:15 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 ?

                J 1 Reply Last reply 15 Jun 2015, 08:51
                0
                • E erez373
                  15 Jun 2015, 08:15

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

                  J Offline
                  J Offline
                  JKSH
                  Moderators
                  wrote on 15 Jun 2015, 08:51 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 15 Jun 2015, 12:37
                  0
                  • J JKSH
                    15 Jun 2015, 08:51

                    @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 15 Jun 2015, 12:37 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))

                    J 1 Reply Last reply 15 Jun 2015, 12:43
                    0
                    • E erez373
                      15 Jun 2015, 12:37

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

                      J Offline
                      J Offline
                      JKSH
                      Moderators
                      wrote on 15 Jun 2015, 12:43 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 22 Jun 2015, 05:22 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

                        2/11

                        14 Jun 2015, 20:25

                        9 unread
                        • Login

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