「Qtの基礎 - 文字コード」の版間の差分

ナビゲーションに移動 検索に移動
23行目: 23行目:
  #include <QTextCodec>
  #include <QTextCodec>
   
   
  // UTF-8へエンコードする場合
  // Shift-JISからUTF-8へデコードする場合
  QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QByteArray SJISdata = "あいうえお";
  QString str      = codec->toUnicode(byteArray);
  QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
  QString str      = codec->toUnicode(SJISdata);
   
   
  // UTF-8からShift-JISへエンコードする場合
  // UTF-8からShift-JISへエンコードする場合
42行目: 43行目:
  #include <QStringConverter>
  #include <QStringConverter>
   
   
  // UTF-8へエンコードする場合
  // Shift-JISからUTF-8へデコードする場合
  QStringDecoder decoder(QStringDecoder::Utf8);
QByteArray SJISdata = "あいうえお";
  QString str = decoder(byteArray);
  QStringDecoder decoder("Shift-JIS");
  QString str         = decoder(SJISdata);
   
   
  // UTF-8からShift-JISへエンコードする場合
  // UTF-8からShift-JISへエンコードする場合

案内メニュー