关于QString显示中文字符不乱码的问题,参见:http://blog.csdn.net/shihoongbo/article/details/47677159
#include <QtCore/QCoreApplication>
#include <iostream>
#include <string>
#include <QString>
#include <qDebug>
std::string QString2stdString(QString qstr)
{
std::string stdStr = qstr.toLocal8Bit().data();
return stdStr;
}
QString stdString2QString(std::string stdStr)
{
QString qstr = QString::fromLocal8Bit(stdStr.c_str());
return qstr;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString qstr = u8"中文字符";
std::cout << QString2stdString(qstr) << std::endl;
std::cout << QString2stdString(qstr).c_str() << std::endl;
std::cout << std::endl;
char *cstr = { "中文字符" };
std::cout << cstr << std::endl;
std::string stdStr(cstr);
std::cout << stdStr << std::endl;
qDebug() << stdString2QString(stdStr) << endl;
return a.exec();
}