Fedora下QT4.8连接MySQL

#include
#include
#include
int main(int argc,char* argv[]){
   QApplication app(argc,argv);
   QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
   QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
   db.setHostName("localhost");
   db.setDatabaseName("test");
   db.setUserName("root");
   db.setPassword("12345678");
   if(!db.open()){
      QMessageBox::warning(0,QObject::tr("无法打开数据库!"),db.lastError().text());
      qDebug()<

你可能感兴趣的:(QT)