#ifndef _LOGIN_H_
#define _LOGIN_H_
#pragma execution_character_set("utf-8")
#include
#include "ui_Login.h"
#include
#include
class Login : public QDialog
{
Q_OBJECT
public:
Login(QWidget *parent = Q_NULLPTR);
~Login();
void initFrom();
private slots:
void connectSqlSlot();
void cannelSlot();
void SavesqlSetting();
void readsqlSetting();
private:
Ui::Login ui;
QSettings *sqlConfigIni;
QString ipQstring;
QString usrNameQstring;
QString passwordQstring;
QString databasesQString;
QString port;
};
#endif // !_LOGIN_H_
#include "Login.h"
Login::Login(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
initFrom();
}
Login::~Login()
{
}
void Login::initFrom()
{
setWindowTitle("数据库登录");
sqlConfigIni = new QSettings("sqlsetting.ini", QSettings::IniFormat);
readsqlSetting();
connect(ui.savedatagbasesBtn, SIGNAL(clicked()), this, SLOT(connectSqlSlot()));
connect(ui.cannelBtn, SIGNAL(clicked()), this, SLOT(cannelSlot()));
}
void Login::connectSqlSlot()
{
SavesqlSetting();
close();
}
void Login::cannelSlot()
{
close();
}
void Login::SavesqlSetting()
{
//向ini文件的第一个节写入内容,ip节下的第一个参数
ipQstring = ui.ServernameEdit->text();
usrNameQstring = ui.usernameEdit->text();
passwordQstring = ui.userpawEdit->text();
databasesQString = ui.databasesEdit->text();
port = ui.portEdit->text();
if (ipQstring == "" || usrNameQstring == "" || passwordQstring == "" || databasesQString == "" || port == "")
{
QMessageBox::information(NULL, "warring:", "请输入完整信息", QMessageBox::No, QMessageBox::Yes);
return;
}
sqlConfigIni->setValue("/ip", ipQstring);
sqlConfigIni->setValue("/name", usrNameQstring);
sqlConfigIni->setValue("/password", passwordQstring);
sqlConfigIni->setValue("/databases", databasesQString);
sqlConfigIni->setValue("/port", port);
//写入完成后删除指针
delete sqlConfigIni;
}
void Login::readsqlSetting()
{
ipQstring = sqlConfigIni->value("/ip").toString();
usrNameQstring = sqlConfigIni->value("/name").toString();
passwordQstring = sqlConfigIni->value("/password").toString();
databasesQString = sqlConfigIni->value("/databases").toString();
port = sqlConfigIni->value("/port").toString();
ui.ServernameEdit->setText(ipQstring);
ui.usernameEdit->setText(usrNameQstring);
ui.userpawEdit->setText(passwordQstring);
ui.databasesEdit->setText(databasesQString);
ui.portEdit->setText(port);
}