0

我正在尝试在 PySide 中制作一个简单的测试应用程序,但我真的不明白我缺少什么。这是到目前为止的代码:

    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()

现在我想做的只是将一个事件连接到按钮。Qt 的文档告诉我我需要做的就是:

btnSend.clicked.connect(self.sendData)

PyCharm 说它在 clicked 中找不到引用,我得到的异常是

TypeError: native Qt signal is not callable

我很(容易)难倒。

4

1 回答 1

0

以下对我来说是正确的:

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')
于 2013-02-14T01:42:27.103 回答