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] Text's Encoding... Which is the best way to resolve this "problem".
Forum Updated to NodeBB v4.3 + New Features

[Solved] Text's Encoding... Which is the best way to resolve this "problem".

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 5.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.
  • H Offline
    H Offline
    Hostel
    wrote on last edited by
    #2

    Did you set text codec? For example:
    @
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dcbasso
      wrote on last edited by
      #3

      I don't make this!
      If I use this on my application it will work for all strings on the application?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hostel
        wrote on last edited by
        #4

        It will work for all strings which will be crated after you use this static methods.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #5

          Wow, This will help a Lot...
          I some parts of my app I make something like

          @
          QString::fromUtf8( "..." );
          or
          QString::fromUtf8( stringVariable );
          @

          Well I will change this right now!
          Thanks a lot.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dcbasso
            wrote on last edited by
            #6

            Now I see the problem!
            I create all codes in Linux and the file appears to be saving in UTF8 and my windows is in PT-BR, thats use ISO-8859-1!
            All codes which uses especial chars got error!

            I will need re-write all files and save as ISO-8859-1.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #7

              It's possible to pass a parameter to compiler to read the Files in UTF-8?!

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hostel
                wrote on last edited by
                #8

                I have my file in utf-8 too. I compile my project under Linux and Windows. I use Qt Creator and mingw on Windows and my app work good if I use
                @
                QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
                QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
                @
                on begin of my program. Your app should work good without converting to ISO-8859-1. Where you have a problem? Paste some code for example issue.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dcbasso
                  wrote on last edited by
                  #9

                  I don't find a way to read the file and set the encoding of file:

                  @
                  QString Database::readCreateTable()
                  {
                  QFile file(":/database/CreateTable.sql");
                  if(!file.open(QIODevice::ReadOnly))
                  {
                  qDebug() << "error opening file: " << file.error();
                  return "";
                  }
                  QTextStream instream(&file);
                  QString createTable =instream.readAll();
                  file.close();
                  return createTable;
                  }
                  @

                  This will work? "http://qt-project.org/doc/qt-4.8/qfile.html#setEncodingFunction":http://qt-project.org/doc/qt-4.8/qfile.html#setEncodingFunction

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    Hostel
                    wrote on last edited by
                    #10

                    Maybe try "setCodec() from QTextStream":http://qt-project.org/doc/qt-4.8/qtextstream.html#setCodec-2 ?

                    "Example of use":http://www.qtcentre.org/threads/2808-Qfile-and-QTextStream but I don't know if this is good.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dcbasso
                      wrote on last edited by
                      #11

                      THis problems with encoding appears only on Windows!
                      I will try to seCodec on QTextStream...

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dcbasso
                        wrote on last edited by
                        #12

                        OK, resolved!
                        I set codec on QTextStream and now is working as expected!

                        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