【发布时间】:2019-08-11 12:42:39
【问题描述】:
我使用 Qt Designer 设计了一个用户界面,并使用信号/槽编辑器添加了信号/槽。我的 UI 中有按钮,信号是 clicked(),插槽是 click()。 pushButton 是我使用 QT Designer 创建的一个小部件。使用 python 3.7 和 QT Designer 5.12
QT Designer 自动生成以下代码:
from PySide2 import QtCore, QtGui, QtWidgets
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName("mainWindow")
self.pushButton = QtWidgets.QPushButton(self.frame_1)
self.pushButton.setObjectName("pushButton")
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.pushButton.click)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
我在class UI_mainWindow() 内添加了以下代码,用于执行pushbutton.click 功能。但我得到错误。请帮我解决这个问题。我需要在我的代码中添加按钮单击功能
class pushButton():
def click(self):
print("Button is clicked")
QT Designer生成的.ui文件:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>56</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>18</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>pushButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>107</x>
<y>76</y>
</hint>
<hint type="destinationlabel">
<x>107</x>
<y>76</y>
</hint>
</hints>
</connection>
</connections>
</ui>
错误:
进程以退出代码 -1073741571 (0xC00000FD) 结束
【问题讨论】:
标签: python qt-designer pyside2