QT访问access中文乱码的问题
-
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("gb18030"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("gb18030"));
(这三个我拿UTF-8和gb18030反复组合了都不行)SoruceTable->setEnabled(true);
//读取access数据库代码
db = QSqlDatabase::addDatabase("QODBC");
QString filePath = SoruceFile->text();
QString dsn = QString("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%1").arg(filePath);
db.setDatabaseName(dsn);if(!db.open()) { QMessageBox::about(0, QObject::tr("读取文件错误"),db.lastError().text()); } else { //获取全部表名 SoruceTable->addItems(db.tables()); }