By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,370 Members | 1,590 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,370 IT Pros & Developers. It's quick & easy.

problem with qthread and signal/slot

P: n/a
i've written a small pyqt code which increments a counter in the backend,
and prints it on the frontend. However, i'm passing a dummy string var
along with it in the signal/slot mechanism. The problem is that from
the 2nd call onwards, the string gets printed, but NOT in the 1st
call. (eg, in the foll code i get:- 1, (2, 'a'), (3, 'a'), ...)
The code is:-
import time
import sys
from PyQt4 import QtGui, QtCore

class Counter(QtCore.QThread):
def __init__(self):
self.cntr = 0
def run(self):
while True:
self.cntr += 1
self.emit(QtCore.SIGNAL("showCntr"), (self.cntr, "a"))
if self.cntr == 10: break
class Gui(QtGui.QDialog):
def __init__(self, parent = None):
QtGui.QDialog.__init__(self, parent)
frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel

self.lCntr = QtGui.QLabel()
loGrd = QtGui.QGridLayout()
loGrd.addWidget(self.lCntr, 0, 0)
def showCntr(self, val):
print val
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
dialog = Gui()
cntr = Counter()
QtCore.QObject.connect(cntr, QtCore.SIGNAL("showCntr"),
dialog.showCntr, QtCore.Qt.QueuedConnection)
Also, this is my 1st ever prog with signals/slots across threads; and
am a newbie to python and pyqt. So please be considerate and kind
enough to point out mistakes/better approaches with the above code.

Thanks a lot!
warm regards,
Pradnyesh Sawant
Be yourself, everyone else is taken. --Anon
Apr 14 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.