pyqt5之信号+槽测试用例-创新互联

在使用pycharm进行编写代码的时候,发现信号设置了connect一个槽,但是测试发现没有起作用,另外,在pycharm编辑器上connect提示没有这个函数,总是找不到原因,后面决定还是对碰到相应的知识点需要做对应的测试用例进行学习和验证。

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的亚东网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

下面这个是对信号+槽的一个典型实例。可以正常按预期运行,在pycharm中connect也显示没有这个函数,应该就是pycharm本身设置和提示的问题,后面忽略它。所以有时候也不能钻牛角尖,pycharm也仅仅是个编辑器而已。

#-*- coding:utf-8 -*- ''' Signal & Slot ''' __author__ = 'Tony Zhu' import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QWidget, QLCDNumber, QSlider,QGridLayout,QLabel,QHBoxLayout, QGroupBox,     QVBoxLayout, QApplication,QProgressBar,QPushButton,QMessageBox) class SignalSlot(QWidget):     def __init__(self):         super(SignalSlot,self).__init__()         self.initUI()     def initUI(self):         self.controlsGroup = QGroupBox("运行样本")         self.lcdNumber = QLCDNumber(self)         self.slider = QSlider(Qt.Horizontal, self)         self.pBar = QProgressBar(self)         vbox = QVBoxLayout()         vbox.addWidget(self.pBar)         vbox.addWidget(self.lcdNumber)         vbox.addWidget(self.slider)         self.controlsGroup.setLayout(vbox)         controlsLayout = QGridLayout()         self.label1 = QLabel("保存状态:")         self.saveLabel = QLabel()         self.label2 = QLabel("运行状态:")         self.runLabel = QLabel()         self.buttonSave = QPushButton("保存")         self.buttonRun = QPushButton("运行")         self.buttonStop = QPushButton("停止")         self.buttonDisconnect = QPushButton("解除关联")         self.buttonConnect = QPushButton("绑定关联")         controlsLayout.addWidget(self.label1,0,0)         controlsLayout.addWidget(self.saveLabel,0,1)         controlsLayout.addWidget(self.label2,1,0)         controlsLayout.addWidget(self.runLabel,1,1)         controlsLayout.addWidget(self.buttonSave,2,0)         controlsLayout.addWidget(self.buttonRun,2,1)         controlsLayout.addWidget(self.buttonStop,2,2)         controlsLayout.addWidget(self.buttonDisconnect,3,0)         controlsLayout.addWidget(self.buttonConnect,3,1)         layout = QHBoxLayout()         layout.addWidget(self.controlsGroup)         layout.addLayout(controlsLayout)         self.setLayout(layout)         self.buttonRun.clicked.connect(self.buttonSave.clicked)         self.slider.valueChanged.connect(self.pBar.setValue)         self.slider.valueChanged.connect(self.lcdNumber.display)         self.buttonSave.clicked.connect(self.showMessage)         self.buttonRun.clicked.connect(self.showMessage)         self.buttonDisconnect.clicked.connect(self.unbindConnection)         self.buttonConnect.clicked.connect(self.bindConnection)         self.buttonStop.clicked.connect(self.stop)         self.setGeometry(300, 500, 500, 180)         self.setWindowTitle('信号和槽')     def showMessage(self):         if self.sender().text() == "保存":             self.saveLabel.setText("Saved")         elif self.sender().text() == "运行":             self.saveLabel.setText("Saved")             self.runLabel.setText("Running")     def unbindConnection(self):         self.slider.valueChanged.disconnect()     def bindConnection(self):         self.slider.valueChanged.connect(self.pBar.setValue)         self.slider.valueChanged.connect(self.lcdNumber.display)     def stop(self):         self.saveLabel.setText("")         self.runLabel.setText("") if __name__ == '__main__':     app = QApplication(sys.argv)     ex = SignalSlot()     ex.show()     sys.exit(app.exec_())

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网页题目:pyqt5之信号+槽测试用例-创新互联
URL网址:https://www.cdcxhl.com/article16/csgpdg.html

成都网站建设公司_创新互联,为您提供营销型网站建设电子商务App设计网页设计公司动态网站网站内链

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设