473,657 Members | 2,436 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(QtCor e.SIGNAL("showC ntr1(PyObject*) "), (cntr,
"a")) # line 1
self.emit(QtCor e.SIGNAL("showC ntr2"), (cntr, "a"))
# line 2
time.sleep(0.2)
class Gui(QtGui.QDial og):
def __init__(self, parent = None):
QtGui.QDialog._ _init__(self, parent)
frameStyle = QtGui.QFrame.Su nken | QtGui.QFrame.Pa nel

self.lCntr = QtGui.QLabel()
self.lCntr.setF rameStyle(frame Style)
loGrd = QtGui.QGridLayo ut()
loGrd.addWidget (self.lCntr, 0, 0)
self.setLayout( loGrd)
self.setWindowT itle(self.tr("C ounter"))
def showCntr1(self, val):
print val, str(val)
self.lCntr.setT ext(str(val))
def showCntr2(self, val):
print val, str(val)
self.lCntr.setT ext(str(val))
if __name__ == "__main__":
app = QtGui.QApplicat ion(sys.argv)
dialog = Gui()
cntr = Counter()
cntr.start()
QtCore.QObject. connect(cntr, QtCore.SIGNAL(" showCntr1(PyObj ect*)"),
dialog.showCntr 1, QtCore.Qt.Queue dConnection)
QtCore.QObject. connect(cntr, QtCore.SIGNAL(" showCntr2"),
dialog.showCntr 1, QtCore.Qt.Queue dConnection)
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 1378

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

Similar topics

3
2083
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 PyQt4 import QtGui , QtCore" and also have to use "QtCore.something". Like when connecting a button: self.connect(self.ui.testButton, QtCore.SIGNAL("clicked()"), self.doSomething)
2
6540
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 a simple graphical interface and binding it to my long existing C library. There was no problem, everything was running fine... ... until I decided to upgrade everything to kubuntu's Edgy and PyQt4. Well, I understood that I need to port my...
2
4040
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. My Script and its functions are in cnt.py. Finally, my main is in pball.py which follows here: import sys from PyQt4 import Qt, QtCore from outputWin import * from cnt import *
2
2251
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 = ("Primary", "priSec") print "tpl:", tpl self.emit(QtCore.SIGNAL("setLabel"), tpl)
2
3258
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 QtGui, QtCore import sys
0
3364
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 MyThread(QtCore.QThread,QtCore.QObject): def __init__(self, parent):
0
982
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
2199
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 slot functions are automatically connected to some signals, using a decorator. In the __init__ function of our newly written class, "connect" is not invoked. I like this style... Unfortunately, I cannot find that manual now.... So anyone have...
3
2556
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 quite clearly i can write a single function to control setting any speed with something like: def setSpeed(self, speed): some code in here to set speed
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.