zoukankan      html  css  js  c++  java
  • QT乱码对策

     1 using namespace std;
     2 
     3 //#pragma execution_character_set("UTF-8")
     4 int main(int argc, char *argv[])
     5 { 
     6 QApplication a(argc, argv);
     7 QString str = QStringLiteral("中文测试");
     8 //str = "中文测试";
     9 qDebug() << str;
    10 //QMessageBox::information(0, "title", str);
    11 char *src = "元数据中文GBK";
    12 
    13 //元数据是gbk或者gb2312 多字节存入QString
    14 //本地编码方式 默认GBK
    15 QString str1 = QString::fromLocal8Bit(src);
    16 qDebug() << "str1 = " << str1;
    17 
    18 //把QString 转为gbk
    19 cout << str1.toLocal8Bit().toStdString() << endl;
    20 //本地处理编码方式,默认是GBK,改为UTF-8
    21 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    22 QString str2 = QString::fromLocal8Bit(str1.toUtf8());
    23 
    24 QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
    25 qDebug() << "str2 = " << str2;
    26 //win api调用qstring作为参数
    27 MessageBox(0, str2.toStdWString().c_str(), L"中文标题",0);
    28 
    29 //vs_cn_codec w;
    30 //w.show();
    31 return a.exec();
    32 }
  • 相关阅读:
    python—虚拟环境搭建
    pytnon—线程,进程
    python——新excel模块之openpyxl
    装饰器——应用
    css样式
    HTML
    广图登陆知网下载资源教程
    使用k-近邻算法改进约会网站的配对效果
    k-近邻算法概述
    机器学习基础
  • 原文地址:https://www.cnblogs.com/linxuemufeng/p/12432526.html
Copyright © 2011-2022 走看看