[Solved] Text's Encoding... Which is the best way to resolve this "problem".
-
Well, I have an application show creates your own database, using a text file with "creates" and "inserts", in this may I make an application who can run on memory stick/pendrive.
But In linux all data that I generate on database is showed in right encoding, but on windows don't show the right text's, I know that is enconding problem.
How can I fix it in simple way? Can be something in encoding database, is something when I show the text on screen....
I have some other messages with same error too...My application uses this chars: "çãáàü...."!
How can I fix it?! If code need ask me and I post how I create the database, or read from database or anything like that.Thanks
-
Did you set text codec? For example:
@
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
@ -
I don't make this!
If I use this on my application it will work for all strings on the application? -
It will work for all strings which will be crated after you use this static methods.
-
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. -
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.
-
It's possible to pass a parameter to compiler to read the Files in UTF-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. -
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
-
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.
-
THis problems with encoding appears only on Windows!
I will try to seCodec on QTextStream... -
OK, resolved!
I set codec on QTextStream and now is working as expected!Thanks