分类: C/C++
2011-08-25 17:42:50
引用
tatic QTextCodec* codec(MYSQL* mysql)
{
return QTextCodec::codecForName("GBK");
#if MYSQL_VERSION_ID >= 32321
QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql));
if (heuristicCodec)
return heuristicCodec;
#endif
return QTextCodec::codecForLocale();
}
引用
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
//QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
引用
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("yourdatabase");
db.setUserName("yourusername");
db.setPassword("yourpassword");
db.open();
db.exec("SET NAMES 'GBK'");
引用
QTextCodec *codec = QTextCodec::codecForName("GBK");
QString strOut = codec->fromUnicode(lineEdit->text()).data();
QString strSql = "UPDATE user SET uinfo = '" + strOut + "'";
db.exec(strSql);