1 Star 0 Fork 4

AmonYR/Qt_TrainTicketingSystem

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
database.h 1.04 KB
Copy Edit Raw Blame History
#ifndef DATABASE_H
#define DATABASE_H
#include <QString>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlRelationalDelegate>
#include <QSqlRelationalTableModel>
#include <QVariantList>
#include <QMessageBox>
#include <QDebug>
//连接数据库
bool connectdatabase(const QString &dbName)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("127.0.0.1"); //连接数据库主机名,这里需要注意(若填的为”127.0.0.1“,出现不能连接,则改为localhost)
db.setPort(3306); //连接数据库端口号,与设置一致
db.setDatabaseName(dbName);
db.setUserName("root"); //数据库用户名,与设置一致
db.setPassword("12345"); //数据库密码,与设置一致
if(!db.open())
{
qDebug() << "can't connect database!";
return false;
}
return true;
}
#endif // DATABASE_H
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Amon152/qt_-train-ticketing-system-q.git
git@gitee.com:Amon152/qt_-train-ticketing-system-q.git
Amon152
qt_-train-ticketing-system-q
Qt_TrainTicketingSystem
master

Search

0d507c66 1850385 C8b1a773 1850385