473,503 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pyqt4 signal/slot using PyObject* and shortcut

Hello, i have the following code:
################################################## ###############
import time
import sys
from PyQt4 import QtGui, QtCore

class Counter(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def run(self):
cntr = 0
while cntr < 10:
cntr += 1
self.emit(QtCore.SIGNAL("showCntr1(PyObject*)"), (cntr,
"a")) # line 1
self.emit(QtCore.SIGNAL("showCntr2"), (cntr, "a"))
# line 2
time.sleep(0.2)
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 showCntr1(self, val):
print val, str(val)
self.lCntr.setText(str(val))
def showCntr2(self, val):
print val, str(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("showCntr1(PyObject*)"),
dialog.showCntr1, QtCore.Qt.QueuedConnection)
QtCore.QObject.connect(cntr, QtCore.SIGNAL("showCntr2"),
dialog.showCntr1, QtCore.Qt.QueuedConnection)
sys.exit(dialog.exec_())
################################################## ###############
If i comment out "line 1", then i get the following output:
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
0.2 0.2
Notice that 0.2 is the time value of the sleep instruction. Why is
this happening?

On the other hand, if i comment out "line 2", then i get the following output:
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
(<refcnt 0 at 0xb7dcd28c>, 'a') (<NULL>, <NULL>)
What i get from the above is that a reference to "cntr" is being
passed, but by the time the gui thread is actually run, both the
values (cntr and "a") have been destroyed, hence the NULL values.
***How do i circumvent this problem?***

Lastly, if i don't comment out any of line 1 or 2, then i get the foll output:
(<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui object at
0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui
object at 0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>,
(<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui object at
0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui
object at 0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>,
(<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui object at
0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui
object at 0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>,
(<__main__.Gui object at 0xb6a8f12c>, (<__main__.Gui object at
0xb6a8f12c>, (<__main__.Gui object at 0xb6a8f12c>, ..........
i don't know what this means??? Can anyone kindly explain what's happening...

I'm using:
python: 2.4.4~c1-0ubuntu1
qt4-dev-tools: not installed
python-qt4: 4.0.1-1ubuntu1
sip4: (4.4.5-2ubuntu1
os: ubuntu edgy
--
warm regards,
Pradnyesh Sawant
--
Be yourself, everyone else is taken. --Anon
Apr 27 '07 #1
0 1366

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

Similar topics

3
2073
by: Tina I | last post by:
I'm trying to 'convert' my self from Qt3 to Qt4 (it rocks!) and one thing seem strange: With Qt3 I usually did "from qt import *", but this does not seem to work with Qt4. I have to use "from...
2
6523
by: AngelOfDarkness | last post by:
Hi guys, unfortunately I am pretty new to Python and Qt and all that. Well, I managed to successfully program a little stuff for my work (computational neuroscientist... no comment please), using...
2
4034
by: Glen | last post by:
Hello, I've written a script in python and put together a simple QFrame with a QTextBrowser with Designer. I've translated the C++ into python using puic4. The .py file is called outputWin.py. ...
2
2241
by: Pradnyesh Sawant | last post by:
Hello, I have a pyqt4 code in which i'm trying the signal/slot mechanism. The (stripped) code is as follows: class D(QtCore.QThread): def __init__(self): QtCore.QThread.__init__(self) tpl =...
2
3242
by: jiang.haiyun | last post by:
Hi, I am having some serious problems with PyQT4, when i run pyqt script, I always get 'Segmentation fault'. the script is simple: ====================== %less qttest.py from PyQt4 import...
0
3344
by: kunalgalav | last post by:
Hi , I am a newbie to python and I am trying to send a signal to my application using a thread. Here's my code: import sys from PyQt4 import QtGui, QtCore from PyQt4.QtCore import * class...
0
972
by: Phil Thompson | last post by:
On Sunday 04 May 2008, Lance Gamet wrote: I think QMainWindow.setCentralWidget() is what you are looking for. The eric4 IDE probably covers most things you'll ever need. Phil
2
2195
by: Bighead | last post by:
I remember when I did UI Design in PyQt4 for the first time, I found a manual. In it, no "connect" was used. Instead, an OO approach is applied, new UI classes inherit from old ones, and all the...
3
2549
by: ff | last post by:
Is it possible to create custom PyQt4 Slots, i have searched high and low to no avail; I have an application that can set animation speed to different levels, i want the user to alter this, now...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.