473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problem with qthread and signal/slot

Hello,
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):
QtCore.QThread.__init__(self)
self.cntr = 0
def run(self):
while True:
self.cntr += 1
self.emit(QtCore.SIGNAL("showCntr"), (self.cntr, "a"))
time.sleep(1)
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()
self.lCntr.setFrameStyle(frameStyle)
loGrd = QtGui.QGridLayout()
loGrd.addWidget(self.lCntr, 0, 0)
self.setLayout(loGrd)
self.setWindowTitle(self.tr("Counter"))
def showCntr(self, val):
print val
self.lCntr.setText(str(val))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
dialog = Gui()
cntr = Counter()
cntr.start()
QtCore.QObject.connect(cntr, QtCore.SIGNAL("showCntr"),
dialog.showCntr, QtCore.Qt.QueuedConnection)
sys.exit(dialog.exec_())
**************************************************
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
0 1922

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Frank Bossy | last post by:
Dear group :) I don't quite understand the meaning of this paragraph in the qt docu (http://doc.trolltech.com/3.1/threads.html): ***SNIP The Signals and Slots mechanism can be used in...
2
by: Artur M. Piwko | last post by:
Is there a way to distinguish if QCheckListItem was checked/unchecked or clicked? -- Grain grows best in shit.
5
by: Leonardo Hyppolito | last post by:
Hello! I am trying to implement a program that uses Threads. I chose the producers and consumers scenario. The producers put a "product" (which is an int number) in a shared storage place of one...
3
by: Memfis | last post by:
What is the best practice for using boost::signal? Should the signal be a public field? Should an accessor method be used? Should there be some special connection methods for every signal, like the...
2
by: Chris Portka | last post by:
I have a problem I've been working on for days now with global variable use. I'm currently using QT for development but this same problem should apply to anytime a C++ object is trying to be used...
2
by: Markus Pitha | last post by:
Hello, I have a window containing a table with some (dynamically created) buttons. I want to change the buttons, when they are clicked, but with dynamically created buttons, this issue seems to...
7
by: psybert | last post by:
Hello everyone, Long time lurker, first time poster. I'm a beginner coder, and I've taught myself everything with the help and expertise of users and websites like this one. I normally figure out...
2
by: exhuma.twn | last post by:
Some code: ---------------------------------------------------------------------- def foobar(w): print w QtCore.QObject,connect( my_line_edit, QtCore.SIGNAL("returnPressed()"), foobar )
1
by: milecimm | last post by:
Hi, I'm binding a sqldtatasource to a gridview to obtain some calculations from the data. However something is wrong for the query because I know the calculations are wrong. I hope I can explain...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.