python - Sending a signal from main function to a thread? -
I am using Pyqt4 to create a GUI in Python. To create a function, I want to send a signal to a thread from the main GUI. I know how to send a signal to the main GUI from thread, but I do not know the reverse thing. Besides, I want to pass a variable with the signal.
Something like this:
class main () def function value = 5 self (matte) (qtcore signal ("signal"), value) square thread ( QtCore.QThread def _init_ (self) Qtcore.QThread._init_ () self.connect (Qt.SIGNAL ("signal (int)"), self.run () def run (self, value): time.sleep ( Value) So every time the signal is transmitted to the main GUI, I want to integrate the function in parallel to the GUI without parallel.
Any help would be appreciated, jet
The object that will be transferred to the thread. You
QtCore.QThread > Do not require more or less something like (Disclaimer: I'm more than C ++ Python): myThread = QtCore.QThread () testObject = YourClassWithSlots () # No parent here Do not have testObject.moveToThread (myThread) myThread.start ()
From all the associated slots> Test objects (with the default connection type) from that point in the thread < Code> myThread will be run.
Useful Links:
Please ez More Details for
Category YourClassWithSlots (QtCore.QObject): @Slot (F) DEF Heavy Task Mode (Self, Value): # Long-term working hours Sleep (value) self.myThread = QtCore.QThread (self) self.testObject = YourClassWithSlots () # There is no parent here self.estObject.moveToThread (myThread) # creates slots to run from this specific thread. Matrate Start (self.connect (Qt.SIGNAL ("Signal (int)"), self.testObject.havyTaskMethod)
Comments
Post a Comment