View Full Version : How to save a file in Windows 1250 code
TomASS
9th February 2010, 20:18
Hi.
I have all my data in Utf8, but now I have to save a file in Windows1250 code. How to conversion a data from utf8 to windows 1250 and save file in windows 1250 code?
Thaks
franz
9th February 2010, 21:31
Have a look at QTextCodec in combination with QTextStream.
TomASS
9th February 2010, 21:39
Could you give me an example, there is only examples to and from Unicode :/
franz
9th February 2010, 21:46
Those are the exact examples you need. toUnicode() returns a QString (QStrings are unicode), fromUnicode() returns a QByteArray, which is your target encoding.
TomASS
9th February 2010, 22:02
Ok, thanks, and what with save file in windows 1250?
TomASS
9th February 2010, 22:19
Now I have:
QString numer_fakt = "222";
QString fileName = QFileDialog::getSaveFileName(this, tr("Zapisz plik"),numer_fakt+".epp",tr("Pliki wymiany danych (*.epp)"));
if(fileName.size()==0) return;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QString dane = "Ę Ã“ Ą Ś Ł Ż Ź Ć Ń ę ó ą ś ł ż ź ć ";
QTextCodec *codec = QTextCodec::codecForName("Windows-1250");
QByteArray encodedString = codec->fromUnicode(dane);
QTextStream out(&file);
out.setCodec(codec);
out << encodedString;
file.close();
what's next? in file I've got only ? ? ? ? sings :/
Lesiok
10th February 2010, 07:04
Now I have:
QString numer_fakt = "222";
QString fileName = QFileDialog::getSaveFileName(this, tr("Zapisz plik"),numer_fakt+".epp",tr("Pliki wymiany danych (*.epp)"));
if(fileName.size()==0) return;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QString dane = "Ę Ã“ Ą Ś Ł Ż Ź Ć Ń ę ó ą ś ł ż ź ć ";
QTextCodec *codec = QTextCodec::codecForName("Windows-1250");
QByteArray encodedString = codec->fromUnicode(dane);
QTextStream out(&file);
out.setCodec(codec);
out << encodedString;
file.close();
what's next? in file I've got only ? ? ? ? sings :/
Change line 14 with
out << dane;or replace lines 12-14 with
file.write(encodedString();
franz
10th February 2010, 15:21
Line 8 is tricky. You'd better specify the encoding it comes from:
QString dane = QString::fromUtf8("Ę Ã“ Ą Ś Ł Ż Ź Ć Ń ę ó ą ś ł ż ź ć ");
If the source file is utf-8 encoded of course.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.