forked from gochao/QT-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
86 lines (71 loc) · 1.89 KB
/
widget.cpp
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
#include "widget.h"
#include <QPushButton>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
b1.setParent(this);
b1.setText("close");
b1.move(50,50);
b2 = new QPushButton(this);
b2->setText("abc");
/*信号接收者, 处理的信号,信号接收者,槽函数*/
connect(&b1,&QPushButton::pressed, this,&Widget::close);
/*自定义槽函数 无返回值*/
connect(b2, &QPushButton::released, this,&Widget::mySlot);
/**/
connect(b2, &QPushButton::released, &b1,&QPushButton::hide);
setWindowTitle("老大");
b3.setParent(this);
b3.setText("切换到子窗口");
b3.move(100,100);
// w.show();
connect(&b3, &QPushButton::released, this, &Widget::changeWin);
//处理子窗口的信号
void (SubWidget::*funSignal)()=&SubWidget::mySignal;
connect(&w, funSignal, this,&Widget::dealSub);
void (SubWidget::*testSignal)(int, QString)=&SubWidget::mySignal;
connect(&w, testSignal, this,&Widget::dealSlot);
resize(400,300);
QPushButton *b4 = new QPushButton(this);
b4->setText("Lambda表达式!");
b4->move(200,100);
// int a=10, b=100;//默认修饰为只读
// connect(b4, &QPushButton::released,
// [=]() mutable//拷贝的过程效率低安全,&是
// {
// b4->setText("我是b4");
// qDebug() << "11111";
// a = 11;
// qDebug() << a << b;
// }
// );
connect(b4, &QPushButton::clicked,
[=](bool isCheck) mutable//拷贝的过程效率低安全,&是
{
qDebug() << isCheck;
}
);
}
void Widget::dealSlot(int a, QString str)
{
qDebug() << a << str.toUtf8().data();
}
void Widget::mySlot()
{
b2->setText("123");
}
void Widget::dealSub()
{
w.hide();
this->show();
}
void Widget::changeWin()
{
//显示子窗口,隐藏本窗口
w.show();
this->hide();
}
Widget::~Widget()
{
}