PyQt4 signal slot method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kunalgalav
    New Member
    • Jun 2008
    • 1

    PyQt4 signal slot method

    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,p arent)
    def run(self):
    a=Emit()
    #self.connect(s elf, QtCore.SIGNAL(' closeEmitApp()' ), self.parent(),Q tCore.SLOT('clo se()') )
    while self.isRunning( ):
    print "We are running"
    self.sleep(10)

    self.emit(QtCor e.SIGNAL('close EmitApp()'))

    class Emit(QtGui.QWid get,MyThread):
    def __init__(self, parent=None):
    QtGui.QWidget._ _init__(self, parent)
    # a = MyThread(app)
    self.setWindowT itle('emit')
    self.resize(250 , 150)
    print 'asdf'
    self.connect(se lf, QtCore.SIGNAL(' closeEmitApp()' ), QtCore.SLOT('cl ose()'),Qt.Queu edConnection )
    #a.start()
    def mousePressEvent (self,event):
    self.emit(QtCor e.SIGNAL('close EmitApp()'))
    mythread.quit()
    app = QtGui.QApplicat ion(sys.argv)
    qb = Emit()
    qb.show()
    mythread = MyThread(app)
    mythread.start( )
    sys.exit(app.ex ec_())

    I am unable to figure out why the thread is unable to send the signal to the Emit class.
    Thank you in advance
    -kunal
Working...