QObject e QThread: criando o "Worker"
This commit is contained in:
@@ -1,14 +1,43 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
from PySide6.QtCore import QObject, Signal, Slot
|
||||||
from PySide6.QtWidgets import QApplication, QWidget
|
from PySide6.QtWidgets import QApplication, QWidget
|
||||||
from ui_workerui import Ui_myWidget
|
from ui_workerui import Ui_myWidget
|
||||||
|
|
||||||
|
|
||||||
|
class Worker1(QObject):
|
||||||
|
started = Signal(str)
|
||||||
|
progressed = Signal(str)
|
||||||
|
finished = Signal(str)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
value = '0'
|
||||||
|
self.started.emit(value)
|
||||||
|
for i in range(5):
|
||||||
|
value = str(i)
|
||||||
|
self.progressed.emit(value)
|
||||||
|
time.sleep(1)
|
||||||
|
self.finished.emit(value)
|
||||||
|
|
||||||
|
|
||||||
class MyWidget(QWidget, Ui_myWidget):
|
class MyWidget(QWidget, Ui_myWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.button1.clicked.connect(self.hardWork1)
|
||||||
|
self.button2.clicked.connect(self.hardWork2)
|
||||||
|
|
||||||
|
def hardWork1(self):
|
||||||
|
self.label1.setText('1 terminado')
|
||||||
|
|
||||||
|
def hardWork2(self):
|
||||||
|
for i in range(5):
|
||||||
|
print(i)
|
||||||
|
time.sleep(1)
|
||||||
|
self.label2.setText('2 terminado')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user