On 2013/8/5 2:20, Vincent Vande Vyvre wrote:
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)
I'm sorry.
In run() function the code below
for dirpath, dirnames, filenames in os.walk(self.root): # What is
'self' here ?
self is current object, isn't it? self.root is a path which the
user will specify.
for filename in filenames:
self.sig_set_label_text.emit('current', self.current()) # where is
'current' ?
# so something
self.current() is a getter, it just returns a member that shows the
path of the current work.
#self.dialog.set_found(str(self.found())) # What is self, and dialog,
and found ?
the main thread is a dialog object.
self.dialog was assigned the dialog object in the __init__ of
worker class.
self.found() is a getter also, it returns the number of meeting the
conditions. self.total() means like this.
#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()
dialog.set_all() and so on just sets the widget's text.
My English is poor, I hopeyou will excuse me.
--
http://mail.python.org/mailman/listinfo/python-list