I am trying to make a simple test application in PySide and I am really not understanding what I am missing. Here's the code so far:
import sys
from PySide import QtCore, QtGui
class IPTest(QtGui.QMainWindow):
def __init__(self):
super(BartonTest, self).__init__()
self.initUI()
def initUI(self):
lblAddress = QtGui.QLabel("IP Address", self)
lineAddress = QtGui.QLineEdit(self)
lblPort = QtGui.QLabel("Port Number", self)
linePort = QtGui.QLineEdit(self)
btnSend = QtGui.QPushButton("Send", self)
btnReceive = QtGui.QPushButton("Receive", self)
lblAddress.move(30, 20)
lblPort.move(30, 60)
lineAddress.move(130, 20)
linePort.move(130, 60)
btnSend.move(30, 100)
btnReceive.move(130, 100)
self.setGeometry(200, 200, 275, 150)
self.setWindowTitle('Send/Receive TCP Test Program')
self.show()
def sendData(self):
fileName, _ = QtGui.QFileDialog.getOPenFileName(self, 'Open CNC Program')
self.data = open(fileName, 'r')
def main():
app = QtGui.QApplication(sys.argv)
bt = IPTest()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Now what I want to do is just connect an event to the Pushbutton. Qt's documentation tells me all I need to do is this:
btnSend.clicked.connect(self.sendData)
PyCharm says it cannot find the reference in clicked and the exception I get is
TypeError: native Qt signal is not callable
I am pretty (easily) stumped.
The following works correctly for me:
import sys
from PySide import QtCore, QtGui
class IPTest(QtGui.QMainWindow):
def __init__(self):
super(IPTest, self).__init__()
self.initUI()
def initUI(self):
lblAddress = QtGui.QLabel("IP Address", self)
lineAddress = QtGui.QLineEdit(self)
lblPort = QtGui.QLabel("Port Number", self)
linePort = QtGui.QLineEdit(self)
btnSend = QtGui.QPushButton("Send", self)
btnReceive = QtGui.QPushButton("Receive", self)
lblAddress.move(30, 20)
lblPort.move(30, 60)
lineAddress.move(130, 20)
linePort.move(130, 60)
btnSend.move(30, 100)
btnReceive.move(130, 100)
btnSend.clicked.connect(self.sendData)
self.setGeometry(200, 200, 275, 150)
self.setWindowTitle('Send/Receive TCP Test Program')
self.show()
def sendData(self):
fileName, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open CNC Program')
if len(fileName) > 0:
self.data = open(fileName, 'r')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.