PDA

View Full Version : codec question



Pingusplus
4th May 2016, 19:06
hello
this time i like know how i can use character like Č,Ž,Švith codec? Im try change from Windows-1251 to ISO 8859-2 but i cant see Č,Ž,Š.

My code: for to base 64
spomin = ui->vnos->toPlainText();
QString src = spomin;
QTextCodec *codec = QTextCodec::codecForName("ISO 8859-2");
QByteArray prevod = codec->fromUnicode(src);
QByteArray text(prevod);
beseda2 = text.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals); // returns "PHA+SGVsbG8/PC9wPg"
ui->vnos->setText(beseda2);

my code for from base 64
spomin = ui->vnos->toPlainText();
QString src = spomin;
QTextCodec *codec = QTextCodec::codecForName("ISO 8859-2");
QByteArray prevod = codec->fromUnicode(src);
QByteArray text(prevod);
beseda2=QByteArray::fromBase64(text, QByteArray::Base64Encoding);
ui->vnos->setText(beseda2);

anda_skoa
4th May 2016, 19:21
Looks at this as a series of steps.

Your "to base 64" series is
- apply codec to transform unicode to ISO-8859-2
- apply Base64 encoding

Your "from base 64" should obviously be the steps in reverse, but instead they are
- apply codec to transform unicode to ISO-8859-2
- unapply base 64 encoding.

So not only are you not applying the steps in the reverse order, you are applying one step twice and not its reverse.

Cheers,
_