2023-08-08 17:47:59 +08:00
|
|
|
#include "widget7.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
Widget7::Widget7(QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle("题目6");
|
|
|
|
setFixedSize(800,600);
|
|
|
|
|
|
|
|
vct = new QVector<QString>();
|
|
|
|
|
|
|
|
btn1 = new QPushButton("张三",this);
|
|
|
|
btn1->move(10,20);
|
|
|
|
btn2 = new QPushButton("李四",this);
|
|
|
|
btn2->move(10,70);
|
|
|
|
btn3 = new QPushButton("王五",this);
|
|
|
|
btn3->move(10,120);
|
|
|
|
btn4 = new QPushButton("赵六",this);
|
|
|
|
btn4->move(10,170);
|
|
|
|
btn5 = new QPushButton("孙七",this);
|
|
|
|
btn5->move(10,220);
|
|
|
|
|
|
|
|
btn_show = new QPushButton("打印",this);
|
|
|
|
btn_show->move(150,20);
|
|
|
|
btn_restart = new QPushButton("重新再来",this);
|
|
|
|
btn_restart->move(150,70);
|
|
|
|
|
2023-08-13 11:47:17 +08:00
|
|
|
// connect(this,&Widget7::my_signal,this,&Widget7::my_handler);
|
|
|
|
connect(this,SIGNAL(my_signal(const QString &)),this,SLOT(my_handler(const QString &)));
|
2023-08-08 17:47:59 +08:00
|
|
|
|
|
|
|
connect(btn1,&QPushButton::clicked,[&]{
|
|
|
|
QString str = btn1->text();
|
|
|
|
emit this->my_signal(str);
|
|
|
|
emit this->studentSelected(str);
|
2023-08-13 11:47:17 +08:00
|
|
|
btn1->setEnabled(false);
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(btn2,&QPushButton::clicked,[&]{
|
|
|
|
QString str = btn2->text();
|
|
|
|
emit this->my_signal(str);
|
|
|
|
emit this->studentSelected(str);
|
2023-08-13 11:47:17 +08:00
|
|
|
btn2->setEnabled(false);
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(btn3,&QPushButton::clicked,[&]{
|
|
|
|
QString str = btn3->text();
|
|
|
|
emit this->my_signal(str);
|
|
|
|
emit this->studentSelected(str);
|
2023-08-13 11:47:17 +08:00
|
|
|
btn3->setEnabled(false);
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(btn4,&QPushButton::clicked,[&]{
|
|
|
|
QString str = btn4->text();
|
|
|
|
emit this->my_signal(str);
|
|
|
|
emit this->studentSelected(str);
|
2023-08-13 11:47:17 +08:00
|
|
|
btn4->setEnabled(false);
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(btn5,&QPushButton::clicked,[&]{
|
|
|
|
QString str = btn5->text();
|
|
|
|
emit this->my_signal(str);
|
|
|
|
emit this->studentSelected(str);
|
2023-08-13 11:47:17 +08:00
|
|
|
btn5->setEnabled(false);
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// 打印学生
|
|
|
|
connect(btn_show,&QPushButton::clicked,[&]()->void{
|
|
|
|
QVector<QString>::iterator it = vct->begin();
|
|
|
|
while(it != vct->end()){
|
|
|
|
qDebug()<<*it;
|
|
|
|
it++;
|
|
|
|
}
|
2023-08-13 11:47:17 +08:00
|
|
|
// for(int i=0;i<vct->size();i++){
|
|
|
|
// qDebug()<<vct->at(i);
|
|
|
|
// }
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(btn_restart,&QPushButton::clicked,[&]()->void{
|
|
|
|
vct->clear(); // 清空容器
|
2023-08-13 11:47:17 +08:00
|
|
|
btn1->setEnabled(true); // 还原按钮可用性
|
|
|
|
btn2->setEnabled(true);
|
|
|
|
btn3->setEnabled(true);
|
|
|
|
btn4->setEnabled(true);
|
|
|
|
btn5->setEnabled(true);
|
2023-08-08 17:47:59 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget7::my_handler(const QString &str)
|
|
|
|
{
|
|
|
|
// qDebug()<<str;
|
2023-08-13 11:47:17 +08:00
|
|
|
if(vct->count(str) == 0) // 当本字符串尚未加入 vct 时,将其加入 vct
|
|
|
|
vct->append(str); // 向 QVector 中添加学生
|
2023-08-08 17:47:59 +08:00
|
|
|
}
|