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):
QtCore.QThread.__init__(self, parent)
QtCore.QObject.__init__(self,parent)
def run(self):
a=Emit()
#self.connect(self, QtCore.SIGNAL('closeEmitApp()'), self.parent(),QtCore.SLOT('close()') )
while self.isRunning():
print "We are running"
self.sleep(10)
self.emit(QtCore.SIGNAL('closeEmitApp()'))
class Emit(QtGui.QWidget,MyThread):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
# a = MyThread(app)
self.setWindowTitle('emit')
self.resize(250, 150)
print 'asdf'
self.connect(self, QtCore.SIGNAL('closeEmitApp()'), QtCore.SLOT('close()'),Qt.QueuedConnection )
#a.start()
def mousePressEvent(self,event):
self.emit(QtCore.SIGNAL('closeEmitApp()'))
mythread.quit()
app = QtGui.QApplication(sys.argv)
qb = Emit()
qb.show()
mythread = MyThread(app)
mythread.start()
sys.exit(app.exec_())
I am unable to figure out why the thread is unable to send the signal to the Emit class.
Thank you in advance
-kunal
|