self.connect(quit, QtCore.SIGNAL('clicked()'), qApp,QtCore.SLOTNameError: name 'qApp' is not defined

python pyqt4 出现如下错误

Traceback (most recent call last):
  File "C:/shibie/pyQtexample.py", line 32, in
    qb=QuitButton()
  File "C:/shibie/pyQtexample.py", line 28, in __init__
    self.connect(quit, QtCore.SIGNAL('clicked()'), qApp,QtCore.SLOT('quit()'))
NameError: name 'qApp' is not defined

 

class QuitButton(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.setGeometry(300, 300, 800, 600)
        self.setWindowTitle('quitButton')
        quit=QtGui.QPushButton('Close',self)
        quit.setGeometry(10,10,60,35)
        self.connect(quit, QtCore.SIGNAL('clicked()'), app,QtCore.SLOT('quit()'))


app=QtGui.QApplication(sys.argv)
qb=QuitButton()
#tooltip=Tooltip()
#tooltip.show()
#icon=Icon()
#icon.show()
qb.show()
sys.exit(app.exec_())

 

只需将原来代码中的qApp修改为app即可(原因我猜的是因为app=QtGui.QApplication(sys.argv))

self.connect(quit, QtCore.SIGNAL('clicked()'), qApp,QtCore.SLOTNameError: name 'qApp' is not defined_第1张图片

你可能感兴趣的:(python3,pyqt4)