-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
45 lines (37 loc) · 989 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "mainwindow.h"
#include "logindialog.h"
#include <QApplication>
#include <QMessageBox>
#include <QtSql/QSqlDatabase>
#include <QtSql/qsqldatabase.h>
#include <QString>
extern QString userName;
extern QString uid;
extern QString status;
extern int power;
void createDefaultConnection() {
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("120.78.141.62");
//db.setHostName("127.0.0.1");
db.setPort(3306);
db.setDatabaseName("community");
db.setUserName("jxnflzc");
db.setPassword("990806");
if (!db.open()) {
QMessageBox::critical(0, "失败", "不能连接到数据库!", QMessageBox::Cancel);
return;
}
}
QSqlDatabase getDefaultConnection() {
return QSqlDatabase::database();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
createDefaultConnection();
getDefaultConnection();
MainWindow w;
LoginDialog loginDlg;
loginDlg.show();
return a.exec();
}