其他
This commit is contained in:
+15
-14
@@ -12,25 +12,26 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
// Widget7 w;
|
||||
// w.show();
|
||||
Widget7 judge1;
|
||||
Widget7 judge2;
|
||||
Widget7 judge3;
|
||||
// Widget7 w;
|
||||
// w.show();
|
||||
|
||||
Widget8 w8;
|
||||
Widget7 judge1;
|
||||
Widget7 judge2;
|
||||
Widget7 judge3;
|
||||
|
||||
judge1.show();
|
||||
judge2.show();
|
||||
judge3.show();
|
||||
Widget8 w8;
|
||||
|
||||
// 建立信号槽连接
|
||||
w8.connect(&judge1,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection);
|
||||
w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection);
|
||||
w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection);
|
||||
judge1.show();
|
||||
judge2.show();
|
||||
judge3.show();
|
||||
|
||||
// 建立信号槽连接
|
||||
w8.connect(&judge1,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection);
|
||||
w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection);
|
||||
w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection);
|
||||
|
||||
|
||||
// w8.show();
|
||||
// w8.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,4 @@ Widget5::Widget5(QWidget *parent) : QWidget(parent)
|
||||
this->setWindowTitle("Winget6消失了");
|
||||
w6->close();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Widget5 : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Widget5(QWidget *parent = nullptr);
|
||||
~Widget5(){ delete w6;}
|
||||
|
||||
private:
|
||||
Widget6 *w6; // Widget6 类对象的指针成员
|
||||
|
||||
@@ -24,37 +24,42 @@ Widget7::Widget7(QWidget *parent) : QWidget(parent)
|
||||
btn_restart = new QPushButton("重新再来",this);
|
||||
btn_restart->move(150,70);
|
||||
|
||||
connect(this,&Widget7::my_signal,this,&Widget7::my_handler);
|
||||
|
||||
// connect(this,&Widget7::my_signal,this,&Widget7::my_handler);
|
||||
connect(this,SIGNAL(my_signal(const QString &)),this,SLOT(my_handler(const QString &)));
|
||||
|
||||
connect(btn1,&QPushButton::clicked,[&]{
|
||||
QString str = btn1->text();
|
||||
emit this->my_signal(str);
|
||||
emit this->studentSelected(str);
|
||||
btn1->setEnabled(false);
|
||||
});
|
||||
|
||||
connect(btn2,&QPushButton::clicked,[&]{
|
||||
QString str = btn2->text();
|
||||
emit this->my_signal(str);
|
||||
emit this->studentSelected(str);
|
||||
btn2->setEnabled(false);
|
||||
});
|
||||
|
||||
connect(btn3,&QPushButton::clicked,[&]{
|
||||
QString str = btn3->text();
|
||||
emit this->my_signal(str);
|
||||
emit this->studentSelected(str);
|
||||
btn3->setEnabled(false);
|
||||
});
|
||||
|
||||
connect(btn4,&QPushButton::clicked,[&]{
|
||||
QString str = btn4->text();
|
||||
emit this->my_signal(str);
|
||||
emit this->studentSelected(str);
|
||||
btn4->setEnabled(false);
|
||||
});
|
||||
|
||||
connect(btn5,&QPushButton::clicked,[&]{
|
||||
QString str = btn5->text();
|
||||
emit this->my_signal(str);
|
||||
emit this->studentSelected(str);
|
||||
btn5->setEnabled(false);
|
||||
});
|
||||
|
||||
// 打印学生
|
||||
@@ -64,16 +69,24 @@ Widget7::Widget7(QWidget *parent) : QWidget(parent)
|
||||
qDebug()<<*it;
|
||||
it++;
|
||||
}
|
||||
// for(int i=0;i<vct->size();i++){
|
||||
// qDebug()<<vct->at(i);
|
||||
// }
|
||||
});
|
||||
|
||||
connect(btn_restart,&QPushButton::clicked,[&]()->void{
|
||||
vct->clear(); // 清空容器
|
||||
btn1->setEnabled(true); // 还原按钮可用性
|
||||
btn2->setEnabled(true);
|
||||
btn3->setEnabled(true);
|
||||
btn4->setEnabled(true);
|
||||
btn5->setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
void Widget7::my_handler(const QString &str)
|
||||
{
|
||||
|
||||
// qDebug()<<str;
|
||||
vct->append(str); // 向 QVector 中添加学生
|
||||
if(vct->count(str) == 0) // 当本字符串尚未加入 vct 时,将其加入 vct
|
||||
vct->append(str); // 向 QVector 中添加学生
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ class Widget7 : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Widget7(QWidget *parent = nullptr);
|
||||
~Widget7()
|
||||
{
|
||||
delete vct;
|
||||
}
|
||||
~Widget7() { delete vct; }
|
||||
|
||||
private:
|
||||
QVector<QString> *vct;
|
||||
QPushButton *btn1,*btn2,*btn3,*btn4,*btn5;
|
||||
|
||||
Reference in New Issue
Block a user