In pyqt, some signals seems not work well
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Sun Aug 4 14:20:56 EDT 2013
Le 04/08/2013 18:06, Jacknaruto a écrit :
> Hi, Guys!
>
> I created a thread class based QThread, and defined some signals to
> update UI through main thread.
>
> the UI used a stackedWidget,someone page named 'progressPage' have a
> progressBar and a Label, the next page named 'resultsPage' shows
> results(some Labels).
>
> When the window showed progressPage, my code that updates progressBar
> was well, but the updating resultsPage's labels signals seems ignored
> by main thread.(I guess, because I added some prints in the slot, it
> wasn't printed)
>
> the code like this:
>
> 1. class worker(QtCore.QThread):
> 2. sig_jump_finish_page = QtCore.pyqtSignal()
> 3. sig_set_label_text = QtCore.pyqtSignal(str, str)
> 4. sig_set_progress_value = QtCore.pyqtSignal(int)
> 5.
>
> 6. for dirpath, dirnames, filenames in os.walk(self.root):
> 7. for filename in filenames:
> 8. self.sig_set_label_text.emit('current', self.current()) # work well
> 9. # so something
>10.
>
> 11. #self.dialog.set_found(str(self.found())) # work well
> 12. #self.dialog.set_all(str(self.total())) # work well
> 13. self.sig_set_label_text.emit('found', str(self.found())) # :(
> 14. self.sig_set_label_text.emit('all', str(self.total())) # :(
>15.
>
> 16. self.sig_jump_finish_page.emit()
>
>
> So I have to update UI directly in the thread(comments Line 11-12
> shows), it looks work well.
>
> I found the difference between line 8 and line 13-14 is line 8
> manipulates current page -progressPage, line 13-14 manipulates next
> page -resultsPage.
>
> Is some wrongs in there?
>
>
>
>
>
Have a look at my comments:
class worker(QtCore.QThread):
sig_jump_finish_page = QtCore.pyqtSignal()
sig_set_label_text = QtCore.pyqtSignal(str, str)
sig_set_progress_value = QtCore.pyqtSignal(int)
for dirpath, dirnames, filenames in os.walk(self.root): # What is 'self'
here ?
for filename in filenames:
self.sig_set_label_text.emit('current', self.current()) # where is
'current' ?
# so something
#self.dialog.set_found(str(self.found())) # What is self, and dialog,
and found ?
#self.dialog.set_all(str(self.total())) # ...
self.sig_set_label_text.emit('found', str(self.found())) # again ?
self.sig_set_label_text.emit('all', str(self.total())) # etc
self.sig_jump_finish_page.emit()
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
More information about the Python-list
mailing list