Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. changing the application codec for all things
Forum Updated to NodeBB v4.3 + New Features

changing the application codec for all things

Scheduled Pinned Locked Moved Unsolved Language Bindings
6 Posts 4 Posters 1.1k Views 1 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.
  • C Offline
    C Offline
    cang
    wrote on last edited by cang
    #1

    Hi,

    I am building a windows application that reads log files and search for the given parameters. The file I am working on produced by Windows-1254 encoding and it contains turkish chars.

    I can not display turkish chars in buttons labels etc. and I can not display the results correclty in my final data too.(which is a basic text that matches my parameters). What I understood is even tho my windows char set is windows-1254 my application is UTF-8. I want to change my application encoding completely to windows-1254. I tried almost everything in internet but no success yet..

    Btw I am using visual studio not qtCreator.

    Thank you for your answers.

    JKSHJ 1 Reply Last reply
    0
    • kkoehneK Offline
      kkoehneK Offline
      kkoehne
      Moderators
      wrote on last edited by kkoehne
      #2

      I understand that you're parsing in a text file, showing the content in the UI, and then writing data in another file. So let's separate the matters.

      Parsing the File

      I assume you're parsing the file with QTextStream? By default QTextStream uses the locale of your current environment. But if you know that the file is in some other locale, you can force that by QTextStream::setCodec. By this you should be able to get the data into the program as UTF-16 (QString).

      Showing the Content

      There should be really no problem in showing Turkish Characters in your user interface.

      Writing the File

      Again, if you use QTextStream, you can force any kind of encoding with QTextStream::setCodec.

      @cang said in changing the application codec for all things:

      my application is UTF-8. I want to change my application encoding completely to windows-1254

      If you're talking about Qt 5 or Qt 6, it's always using Unicode internally. Strings are represented as UTF-16, to be precise. There's no way to change that.

      Director R&D, The Qt Company

      1 Reply Last reply
      3
      • C cang

        Hi,

        I am building a windows application that reads log files and search for the given parameters. The file I am working on produced by Windows-1254 encoding and it contains turkish chars.

        I can not display turkish chars in buttons labels etc. and I can not display the results correclty in my final data too.(which is a basic text that matches my parameters). What I understood is even tho my windows char set is windows-1254 my application is UTF-8. I want to change my application encoding completely to windows-1254. I tried almost everything in internet but no success yet..

        Btw I am using visual studio not qtCreator.

        Thank you for your answers.

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

        @cang said in changing the application codec for all things:

        I want to change my application encoding completely to windows-1254.

        To clarify @kkoehne's point: You don't need to (and you cannot) change your application encoding to Windows-1254. Instead, you need to tell your text parser to decode your Windows-1254 log file. When you do this correctly, your application can display Turkish characters no problem. (It can even display Chinese, Arabic, Russian, etc. characters at the same time!)

        Can you show us your file-reading code?

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

        1 Reply Last reply
        3
        • C Offline
          C Offline
          cang
          wrote on last edited by
          #4

          @kkoehne actually I am showing the results in qTextEdit and parsing the file with an external json library and keeping my data in the memory. I am keeping the result in std::string before I pass it into qTextEdit->setText("myStdString"). In debugger my string looks fine with turkish chars but in qTextEdit its corrupt. Your solution is keeping my data in QString and decoding with utf16 if I understand correctly.

          @JKSH my file parser is very basic. I read my file with getLine and when It becomes a valid json object I am parsing it with rapidjson and then keeping this object in memory.

          aha_1980A 1 Reply Last reply
          0
          • C cang

            @kkoehne actually I am showing the results in qTextEdit and parsing the file with an external json library and keeping my data in the memory. I am keeping the result in std::string before I pass it into qTextEdit->setText("myStdString"). In debugger my string looks fine with turkish chars but in qTextEdit its corrupt. Your solution is keeping my data in QString and decoding with utf16 if I understand correctly.

            @JKSH my file parser is very basic. I read my file with getLine and when It becomes a valid json object I am parsing it with rapidjson and then keeping this object in memory.

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by aha_1980
            #5

            Hi @cang,

            std::string is good to keep pure ASCII. QString however, is 16 bit Unicode and can handle the special non-ASCII characters. You can pass it to every Qt object without problems.

            You just need to make sure, that everything you convert to a QString is handled with correct encoding.

            I am parsing it with rapidjson and then keeping this object in memory.

            Any reason you don't use Qt JSON?

            By the way, typically JSON is in UTF-8 encoding. Using other encodings might give you extra work.

            Regards

            Qt has to stay free or it will die.

            1 Reply Last reply
            3
            • C Offline
              C Offline
              cang
              wrote on last edited by
              #6

              @aha_1980 Hi,

              I passed my string into QString constructor like this "QtextEdit->setText(Qstring().fromLocal8bit(mystring.c_str()); and my problem solved. I believe this is the only way I can work with.

              About QtJson I never tried actually. I searched for the top 5 cpp json parser and benchmarked every one of them. Rapidjson was the fastest. My log files are like 5 gb per file and if you think QtJson is faster I can try.

              1 Reply Last reply
              0

              • Login

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