Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Problem with encoding

    General and Desktop
    2
    3
    460
    Loading More Posts
    • 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.
    • D
      danifujii last edited by

      Hi guys.
      I am having a problem with, I think, the encoding in Qt. I try to write a file with some symbols but it seems that Qt is not able to read them and instead replaces them with "?". The symbol I need in particular is "¬". I realize that something is weird before writing the file, as doing qDebug() already shows the change.
      Here is an example:

              tmp.push_front("¬");
              qDebug() << tmp;
      

      Where tmp is qString and when doing qDebug it shows a "?" where there should be a "¬".
      I tried so many encodings (UTF-8,UTF-16,ISO-8859) yet no one seems to work.
      I am changing this in Tools > Options >Text Editor > Behaviour > Default encoding.

      Thanks!

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @danifujii last edited by raven-worx

        @danifujii
        This is - as you already noticed - a very error prone approach. Since it heavily depends on the file encoding you are using. The next developer may save the file in another encoding in the worst case.

        So you should use the unicode value directly:

        QChar(0x00AC)    // or QString::fromUtf8("\u00AC")
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        D 1 Reply Last reply Reply Quote 0
        • D
          danifujii @raven-worx last edited by

          @raven-worx Oh thank you! Didn't even think about doing something like that. It worked perfectly, thanks!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post