4 Star 0 Fork 0

刘云龙/软件工程

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zhuchejiemian1.cpp 3.58 KB
一键复制 编辑 原始数据 按行查看 历史
刘云龙 提交于 2022-08-15 03:38 . 界面代码
#include "zhuchejiemian1.h"
#include "ui_zhuchejiemian1.h"
#include<QString>
#include<QMessageBox>
#include<QFile>
#include<QTextStream>
#include<QDebug>
#include"mainwindow.h"
zhuchejiemian1::zhuchejiemian1(QWidget *parent) :
QWidget(parent),
ui(new Ui::zhuchejiemian1)
{
ui->setupUi(this);
QPixmap pixmap = QPixmap(":/image/801A70821CAD5084A8C4FC2774B39635.jpg").scaled(this->size());
QPalette palette;
palette.setBrush(QPalette::Window,QBrush(pixmap));
this->setPalette(palette);
QList<QString> stu_lines;
QFile file("E:\\kaifashijian\\kaifa\\社团名称.txt");
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QMessageBox::critical(this,"错误","文件打开失败,信息没有保存","确认");
}
QTextStream in(&file);
in.setCodec("UTF-8");//读取中文
while(!in.atEnd())
{
QString line=in.readLine();
stu_lines.append(line);
}
file.close();
int i=0;
for(i=0;i<stu_lines.length();i++)
{
QString line=stu_lines.at(i);
line=line.trimmed();
}
}
zhuchejiemian1::~zhuchejiemian1()
{
delete ui;
}
void zhuchejiemian1::on_yes_clicked()
{
QString name = "111";
QString account = ui->account->text();//获取账号
QString password = ui->password->text();//获取密码
QString password2 = ui->password_2->text();//获取确认密码
if(jiancha(name,account)==1)
{
QMessageBox::critical(this,"错误","账号已经存在,请重新输入","确认");
}
else
{
if(password!=password2)
{
QMessageBox::critical(this,"错误","两次输入的密码不一致,请检查后重新输入","确认");
}
else if(account==NULL||password==NULL||password2==NULL)
{
QMessageBox::critical(this,"错误","信息填写不全,请检查后重新输入","确认");
}
else if(password==password2)
{
QString content=name+" "+account+" "+password+" "+password2+"\n";
writeToFile2(content);//将信息写入文件;
QMessageBox msgBox;
msgBox.setText("注册成功.");
msgBox.exec();
this->close();
MainWindow *p = new MainWindow();
p->show();
}
}
}
void zhuchejiemian1::on_return_2_clicked()
{
this->close();
MainWindow *p = new MainWindow();
p->show();
}
void zhuchejiemian1::writeToFile2(QString cnt)
{
QFile file("E:\\kaifashijian\\kaifa\\注册信息1.txt");
if(!file.open(QIODevice::Append|QIODevice::Text))
{
QMessageBox::critical(this,"错误","文件打开失败,信息没有保存","确认");
return ;
}
QTextStream out(&file);
out<<cnt;
file.close();
}
int zhuchejiemian1::jiancha(QString name,QString account)
{
QList<QString> stu_lines;
QFile file("E:\\kaifashijian\\kaifa\\注册信息1.txt");
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QMessageBox::critical(this,"错误","文件打开失败,信息没有保存","确认");
return 0;
}
QTextStream in(&file);
while(!in.atEnd())
{
QString line=in.readLine();
stu_lines.append(line);
}
file.close();
int i=0;
for(i=0;i<stu_lines.length();i++)
{
QString line=stu_lines.at(i);
line=line.trimmed();
QStringList subs=line.split(" ");
if(account==subs.at(1))
{
return 1;
}
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Big_decision/software-engineering.git
git@gitee.com:Big_decision/software-engineering.git
Big_decision
software-engineering
软件工程
master

搜索帮助