马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 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();
}
|