Skip to content

Instantly share code, notes, and snippets.

@plq
Created January 10, 2012 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plq/1588339 to your computer and use it in GitHub Desktop.
Save plq/1588339 to your computer and use it in GitHub Desktop.
Qt ile encoding testi.
#include <QString>
#include <QTextCodec>
#include <iostream>
int main(int argc, char *argv[]) {
const char *p = "kıracağım";
// Kaynak kod editörünün encoding'inin utf8 olduğunu varsayarsak;
QTextCodec *utf8 = QTextCodec::codecForName("utf8");
QTextCodec *cp_1254 = QTextCodec::codecForName("Windows-1254");
QString str = utf8->toUnicode(p); // <- simdi elimizde dogru yorumlanmis string var
QByteArray byte_array = cp_1254->fromUnicode(str); // simdi elimizde cp-1254 var
for (const char *p2=byte_array.constData(); *p2; ++p2) {
std::cout << std::hex << (unsigned)*p2 << " ";
}
std::cout << std::endl;
// ya da soyle gostereyim:
std::cout << cp_1254->fromUnicode(str).toPercentEncoding().constData() << std::endl; // cp-1254'u percent encoding yaptik
std::cout << utf8->fromUnicode(str).toPercentEncoding().constData() << std::endl; // utf8'i percent encoding yaptik
}
6b fffffffd 72 61 63 61 fffffff0 fffffffd 6d
k%FDraca%F0%FDm
k%C4%B1raca%C4%9F%C4%B1m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment