一、Qt-亂碼問題
本人在數據庫操作時,出現亂碼,苦思冥想,終於找到解決方案了。廢話不多,上代碼:
新建一個空的工程,在主函數中添加如下代碼:
#include <QApplication>
#include <QTextCodec>
#include <QDebug>
#include <QString>
int main(int argc, char *argv[])
{
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QApplication a(argc, argv);
QString str = a.tr("小明");
qDebug() << str;
return 0;
}該例子可能很簡單,但是應用面非常廣,譬如:傳遞函數參數數據庫查詢 void select(QString user,QString age),select("小明","19")出現下列亂碼,"select Content from table where user = ' '??°????o?'" and age ="19"