当前位置:网站首页>QT realizes signal transmission and reception between two windows

QT realizes signal transmission and reception between two windows

2022-07-05 09:55:00 Sunqk5665

It mainly uses the correlation implementation method of signal and slot

1、 Implementation process

1、 Create a new one Widget, And then build another one QMainWindow.
2、 stay mainwindow.h Custom signal in header file , Use it when declaring signals keyword , stay public、private and protect And so on , Because the signal defaults to public function .
 Insert picture description here
3、 stay mianwindow.ui Add spinbox And a button.
4、 Then go to pushbutton The slot corresponding to the stand-alone signal of , Add the function code as follows :
 Insert picture description here
So click the button to get spinBox The value in , And send the obtained value . It is actually sent to memory , Wait for the slot function to get .
5、 stay widget.h Add a custom slot declaration in the header file :
 Insert picture description here
6、 And then in widget.ui Drag in a Lable, Used to receive the previously sent value .
 Insert picture description here
7、 I'll see you next widget.cpp The implementation of custom slots in the source file , Is to capture the signal transmitted in front , Display values in lable in .
 Insert picture description here

8、 The next in widget.cpp Associate the signal with the slot in the source file .
 Insert picture description here

2、 Running effect

 Insert picture description here
 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[Sunqk5665]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140535206459.html