【1】QString 转换为string

1     QString qString("好好学习天天向上");
2     std::string stdString = qString.toStdString();
3     QTextCodec* pCode = QTextCodec::codecForName("gb18030");
4     // 如果code为0,表示在运行的机器上没有装gb18030字符集。不过一般的中文windows系统中都安装了这一字符集
5     if (NULL != pCode)
6     {
7         stdString = pCode->fromUnicode(qString).data();
8     }

【2】string 转换为QString

1     std::string stdString = "好好学习天天向上";
2     QString strQ = QString::fromLocal8Bit(stdString.c_str());

相关文章:

  • 2022-03-03
  • 2021-07-29
  • 2021-07-18
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-25
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
相关资源
相似解决方案