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. Problem with encoding
Forum Updated to NodeBB v4.3 + New Features

Problem with encoding

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 655 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.
  • D Offline
    D Offline
    danifujii
    wrote on last edited by
    #1

    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-worxR 1 Reply Last reply
    0
    • D danifujii

      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-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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
      0
      • raven-worxR 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")
        
        D Offline
        D Offline
        danifujii
        wrote on last edited by
        #3

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

        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