I use QT Creator, I create a console application. All in the know. OS - Windows XP.
I created a QString that contains several Hungarian characters. Most Hungarian characters do not require Unicode, but characters that have double slashes for emphasis require Unicode.
I am trying to write the contents of a QString to a file, but my unicode characters lose their accents in the file. In other words, Unicode information is lost along the way.
My code is below.
#include <QtCore/QCoreApplication>
#include <QString>
#include <QTextStream>
#include <QDate>
#include <QFile>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QString szqLine = "NON-UnicodeIsOK: áéüúöóí NEED-Unicode: űő";
QFile file("out.txt");
if ( !file.open(QIODevice::WriteOnly | QIODevice::Text) ){
return 1;
}
QTextStream out(&file);
out.setCodec("UTF-8");
out << szqLine << endl;
file.close();
return app.exec();
}
source
share