-
Qt Signal Slot Custom Class카테고리 없음 2021. 3. 10. 06:11
Qt documentation: Multi window signal slot connection. A simple multiwindow example using signals and slots. There is a MainWindow class that controls the Main Window view. For example if you want to link a value changed event then you would emit a signal from within the class and then use that signal with the QObject::connect to link to a slot within class as well. I have created a class called EmitterTest that has a function within it called.
PermalinkJoin GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upFind fileCopy path Cannot retrieve contributors at this timeQt Connect Class Slots To Designer Signals
#!/usr/bin/env python # coding: utf-8 # 예제 내용 # * 시그널 선언시 인자 타입을 선언 후 값 전달하기 import sys from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QLabel from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QBoxLayout from PyQt5.QtCore import Qt from PyQt5.QtCore import QThread from PyQt5.QtCore import pyqtSignal import string import time import random __author__ ='Deokyu Lim <hong18s@gmail.com>' classOtpTokenGenerator(QThread): '' 1초마다 남은 시간 5초마다 변화된 OTP 코드를 시그널로 전달 '' # 사용자 정의 시그널 선언 value_changed = pyqtSignal(str, name='ValueChanged') expires_in = pyqtSignal(int, name='ExpiresIn') EXPIRE_TIME=5 def__init__(self): QThread.__init__(self) self.characters =list(string.ascii_uppercase) self.token =self.generate() def__del__(self): self.wait() defgenerate(self): random.shuffle(self.characters) return''.join(self.characters[0:5]) defrun(self): '' 토큰 값과 남은 시간을 실시간으로 전송(emit)한다. :return: '' self.value_changed.emit(self.token) # 시작 후 첫 OTP코드 전달 whileTrue: t =int(time.time()) %self.EXPIRE_TIME self.expires_in.emit(self.EXPIRE_TIME- t) # 남은 시간을 전달 if t !=0: self.usleep(1) continue # 바뀐 토큰 값을 전달 self.token =self.generate() self.value_changed.emit(self.token) self.msleep(1000) classForm(QWidget): def__init__(self): QWidget.__init__(self, flags=Qt.Widget) self.lb_token = QLabel() self.lb_expire_time = QLabel() self.otp_gen = OtpTokenGenerator() self.init_widget() self.otp_gen.start() definit_widget(self): self.setWindowTitle('Custom Signal') form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self) self.setLayout(form_lbx) # 시그널 슬롯 연결 self.otp_gen.ValueChanged.connect(self.lb_token.setText) self.otp_gen.ExpiresIn.connect(lambdav: self.lb_expire_time.setText(str(v))) form_lbx.addWidget(self.lb_token) form_lbx.addWidget(self.lb_expire_time) if__name__'__main__': app = QApplication(sys.argv) form = Form() form.show() exit(app.exec_()) Copy lines Copy permalink
Overview
In the Custom Type Example, we showed how to integrate custom types with the meta-object system, enabling them to be stored in QVariant objects, written out in debugging information and used in signal-slot communication.
In this example, we demonstrate that the preparations made to the
Message
class and its declaration with Q_DECLARE_METATYPE() enable it to be used with direct signal-slot connections. We do this by creating aWindow
class containing signals and slots whose signatures includeMessage
arguments.The Window and Message Class Definitions
We define a simple
Window
class with a signal and public slot that allow aMessage
object to be sent via a signal-slot connection:The window will contain a text editor to show the contents of a message and a push button that the user can click to send a message. To facilitate this, we also define the
sendMessage()
slot. We also keep aMessage
instance in thethisMessage
private variable which holds the actual message to be sent.The
Message
class is defined in the following way:The type is declared to the meta-type system with the Q_DECLARE_METATYPE() macro:
This will make the type available for use in direct signal-slot connections.
The Window Class Implementation
The
Window
constructor sets up a user interface containing a text editor and a push button.The button's clicked() signal is connected to the window's
sendMessage()
slot, which emits themessageSent(Message)
signal with theMessage
held by thethisMessage
variable:Wild vegas casino no deposit bonus codes for new players. Nov 08, 2019 $25 no deposit bonus for Cool Cat Casino & Wild Vegas Casino Your bonus code: BW6TB3T $25 No deposit bonus + 20 free spins on Stardust Slot 30X Wager $100 Maximum Cashout. If your last transaction was a free chip then please be sure to make a deposit before claiming this one or your winnings will be considered void and you will not be able to cash out. Moreover, the fact that this online casino is owned by Cool Cat that has not so good reputation makes us advise you to play solely for fun. USA Players accepted. Wild Vegas Casino no deposit bonus codes. $88 no deposit bonus for new players. Bonus code: 88CASINOFORUM2. More Wild Vegas Casino no. Jul 17, 2019 Bonus code: MARIACHI25. Casino name: Wild Vegas Casino 25 free spins valid for The Mariachi5 slot. No multiple accounts or free bonuses in a row are allowed. If your last transaction was a free bonus please make a deposit before using this bonus. RTGBonus.eu reviews the promoted Wild Vegas Casino with very strict rules. We continuously try to test, play and use our exclusive no deposit bonus codes and or its own no deposit bonus codes, free spins codes and any other match bonus offer. All the previous are regularly offered by Wild Vegas Casino.
Torrent files slot games downloads. We implement a slot to allow the message to be received, and this also lets us set the message in the window programatically:
In this function, we simply assign the new message to
thisMessage
and update the text in the editor.Making the Connection
In the example's
main()
function, we perform the connection between two instances of theWindow
class:We set the message for the first window and connect the
messageSent(Message)
signal from each window to the other'ssetMessage(Message)
slot. Since the signals and slots mechanism is only concerned with the type, we can simplify the signatures of both the signal and slot when we make the connection.When the user clicks on the Send message button in either window, the message shown will be emitted in a signal that the other window will receive and display.
Further Reading
Although the custom
Message
type can be used with direct signals and slots, an additional registration step needs to be performed if you want to use it with queued signal-slot connections. See the Queued Custom Type Example for details.More information on using custom types with Qt can be found in the Creating Custom Qt Types document.
Qt Signal Slot Thread
Files:
Qt Signal Slot Example
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.