This repository was archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectConfig.cpp
More file actions
54 lines (54 loc) · 2.06 KB
/
Copy pathconnectConfig.cpp
File metadata and controls
54 lines (54 loc) · 2.06 KB
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
46
47
48
49
50
51
52
53
54
#include "connectConfig.h"
void connectConfig::link()
{
//查重
if (QSqlDatabase::contains(connectLine->text())) {
QMessageBox::warning(NULL, QStringLiteral("Warn"),
"Connect name repetition\nPlease change connect",
QMessageBox::Yes);
return;
}
db = new QSqlDatabase(QSqlDatabase::addDatabase(kindBox->currentText(), connectLine->text()));
//设置连接信息
db->setHostName(hostLine->text());
db->setDatabaseName(dataLine->text());
db->setUserName(userLine->text());
db->setPort(portLine->text().toUInt());
db->setPassword(passwordLine->text());
//链接
if (!db->open()) {
QMessageBox::warning(NULL, QStringLiteral("Error"),
db->lastError().text(),
QMessageBox::Yes);
delete db;
db = nullptr;
QSqlDatabase::removeDatabase(connectLine->text());
}
else close();
}
connectConfig::connectConfig(QWidget* parent)
:QDialog(parent, Qt::WindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowCloseButtonHint)),
layout(new QFormLayout(this)),
kindBox(new QComboBox(this)),
hostLine(new QLineEdit("localhost", this)),
dataLine(new QLineEdit("Alumni", this)),
userLine(new QLineEdit("AnglesD", this)),
portLine(new QLineEdit("3306", this)),
passwordLine(new QLineEdit(this)),
connectLine(new QLineEdit(this)),
btn(new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::Cancel, this)),
db(nullptr)
{
setWindowTitle("Connect Config");
layout->addRow("Model:", kindBox); layout->addRow("Connect:", connectLine);
layout->addRow("Host:", hostLine); layout->addRow("Data:", dataLine);
layout->addRow("User:", userLine); layout->addRow("Port:", portLine);
layout->addRow("Password:", passwordLine); layout->addRow(btn);
setLayout(layout);
btn->button(QDialogButtonBox::Yes)->setText(tr("Connect"));
kindBox->addItem("QMYSQL");
passwordLine->setEchoMode(QLineEdit::Password);
portLine->setValidator(new QIntValidator(0, 25565, portLine));
connect(btn, &QDialogButtonBox::accepted, this, &connectConfig::link);
connect(btn, &QDialogButtonBox::rejected, this, &connectConfig::close);
}