Qt连接MYSQL数据库
本帖最后由 ~风介~ 于 2015-11-20 20:03 编辑//xxx.pro
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-21T13:23:08
#
#-------------------------------------------------
QT += core\
sql
QT -= gui
TARGET = mysqlTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
+++//main.cpp
#include <QCoreApplication>
#include <QtSql>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("tttt");
db.setUserName("root");
db.setPassword("******");
if(db.open())
qDebug() << "OK!";
else
{
qDebug() << "Error!";
return a.exec();
}
return a.exec();
}
支持版主:lol:
页:
[1]