//插入记录
QSqlQuery query;
QByteArray sql = "insert into person values(1, 'hello', '你好!')";
QTextCodec *codec = QTextCodec::codecForName("GBK");
QString string = codec->toUnicode(sql);
query.exec(string);
//读入记录
QSqlQuery query("select * from person");
while (query.next()) {
QString string = query.value(2).toString();;
QMessageBox::information(0, "infa", string, QMessageBox::Ok);
}
QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
//字符转换
char *string = "中文和English混和字符串!"
QTextCodec* gbk_codec = QTextCodec::codecForName("GBK");
QString gbk_string = gbk_codec->toUnicode(string);
QLabel *label = new QLabel(gbk_string);
//文件转换
QFile file("default.txt");
QTextStream stream(file,QIODevice::ReadOnly);
stream.setCodeC( QTextCodec::codecForName("GB2312") );
stream.readAll();
QT4.6.0中文乱码
最新推荐文章于 2024-08-22 20:36:55 发布