-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer.cpp
More file actions
101 lines (89 loc) · 2.52 KB
/
Copy pathanswer.cpp
File metadata and controls
101 lines (89 loc) · 2.52 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "answer.h"
#include "ui_answer.h"
#include<QMessageBox>
#include<QList>
#include<QMap>
#include<QDebug>
#include"newfriend.h"
#include"user_info.h"
extern QList<application>applyList;
extern QList <USER> list;
extern USER succeed;//单独全局变量已登录的用户
extern QMap <QString,QString>corre;
extern QList<USER>temp;
extern USER selected;
Answer::Answer(QWidget *parent) :
QDialog(parent),
ui(new Ui::Answer)
{
ui->setupUi(this);
this->setWindowTitle("申请");
if(selected.verti_way==1)ui->question->setText("无需回答问题,直接申请");
else{
ui->question->setText(selected.question);
}
}
Answer::~Answer()
{
delete ui;
}
void Answer::on_send_clicked()
{
if(selected.phone==succeed.phone){
QMessageBox::critical(this,tr("提示"),tr("不能向自己申请!"));
this->close();
newFriend *pic=new newFriend;
pic->show();
return;
}
for(int i=0;i<succeed.contact.size();i++){
if(selected.phone==succeed.contact[i]){
QMessageBox::critical(this,tr("提示"),tr("您已添加过该用户,不可重复添加!"));
this->close();
newFriend *pic=new newFriend;
pic->show();
return;
}
}
if(selected.verti_way==1){
application app;
app.from=succeed.phone;
app.to=selected.phone;
app.accepted="2";
app.answer="";
applyList<<app;
}
else{
if(ui->answerEdit->text()==NULL){
QMessageBox::critical(this,tr("提示"),tr("回答不能为空!"));
return;
}
else if(ui->answerEdit->text().indexOf(" ")!=-1){
QMessageBox::critical(this,tr("提示"),tr("回答不能带空格!"));
return;
}
else{
application app;
app.from=succeed.phone;
app.to=selected.phone;
app.accepted="2";
app.answer=ui->answerEdit->text();
applyList<<app;
}
}
QFile file("application.txt");
bool isok=file.open(QIODevice::WriteOnly|QIODevice::Truncate);
if(isok){
QTextStream out(&file);
out.setCodec("UTF-8");
for(int i=0;i<applyList.size();i++){
out<<applyList[i].from<<" "<<applyList[i].to<<" "<<applyList[i].accepted<<" "<<applyList[i].answer<<endl;
}
}
else qDebug()<<"error";
file.close();
this->close();
newFriend *pic=new newFriend;
applyList.setSharable(true);
pic->show();
}