-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
32 lines (30 loc) · 822 Bytes
/
Copy pathmain.cpp
File metadata and controls
32 lines (30 loc) · 822 Bytes
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
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
//连接到SQLServer
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");//数据库驱动类型sqlserver
db.setHostName("(local)");//选择本地主机,或则127.0.0.1
db.setDatabaseName("hospital");
db.setUserName("sa");
db.setPassword("1");
if(!db.open())
{
qDebug()<<db.lastError().text();
QMessageBox::critical(&w,"Informatinon",db.lastError().text());
}
else
{
qDebug()<<"database open success!";
QMessageBox::information(&w,"Information","连接成功");
}
w.show();
return a.exec();
}