PyQT SIGNAL的问题 [英] Problems with PyQT SIGNAL
问题描述
我在运行以下程序时遇到问题。我希望当我按下按钮时启动功能。但按下按钮之前功能开始。这是我的代码
gui.py
来自PySide.QtCore导入的
*来自PySide.QtGui导入的
*
导入系统
import showGui
导入时间
类Dialog(QDialog,showGui.Ui_Dialog):
def __init __(自我,父=无):
super(对话,自我).__ init __(父母)
self .setupUi(self)
self.connect(self.showButton,SIGNAL('clicked()'),self.processData())
#def ShowMessageBox(个体经营):
#QMessageBox.information(自我,'你好','你好'+自我.nameEdit.text())
def processData(个体经营):
time.sleep(6)
QMessageBox.information(self,'Done!','Done')
app = QApplication(sys.argv)
form =对话框()
form.s怎么()
app.exec_()
showGui.py
# - * - 编码:utf-8 - * -
#通过读取ui文件'show.ui'生成的表单实现>
#
#创建时间:2008年4月8日星期二14:02:39
#by:PyQt4 UI代码生成器4.10.4
#
#警告!此文件中的所有更改都将丢失!
来自PySide导入QtCore,QtGui
尝试:
_fromUtf8 = QtCore.QString.fromUtf8
除了AttributeError:
def _fromUtf8(s):
返回s
试试:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context,text,disambig) :
返回QtGui.QApplication.translate(context,text,disambig,_encoding)
除了AttributeError:
def _translate(context,text, disambig):
返回QtGui.QApplication.translate(context,text,disambig)
class Ui_Dialog(object):
def setupUi(self,Dialog):
Dialog.setObjectName(_fromUtf8(Dialog))
Dialog.resize(379,156)
self.nameEdit = QtGui.QLineEdit(Dialog)
self.nameEdit.setGeometry(QtCore.QRect(30,40,131, 31))
self.nameEdit.setText(_fromUtf8())
self.nameEdit.setObjectName(_fromUtf8(nameEdit))
self.showButton = QtGui.QPushButton(Dialog)
self.showButton.setGeometry(QtCore.QRect(200,40,71,31))
self.showButton .setObjectName(_fromUtf8(showButton))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
Dialog.setTabOrder(self.showButton,self.nameEdit)
def retranslateUi(self,Dialog):
Dialog.setWindowTitle(_translate(Dialog,Dialog,None))
self.nameEdit.setPlaceholderText(_translate(Dialog,你叫什么名字?,无)) />
self.showButton.setText(_tr
I have problems with runing following program. I want that when i press push button it start function. but function start before i press the button. here is my code
gui.py
from PySide.QtCore import *
from PySide.QtGui import *
import sys
import showGui
import time
class Dialog(QDialog, showGui.Ui_Dialog):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setupUi(self)
self.connect(self.showButton, SIGNAL( 'clicked()' ), self.processData())
# def ShowMessageBox(self):
# QMessageBox.information(self,'Hello','Hello there' + self.nameEdit.text())
def processData(self):
time.sleep(6)
QMessageBox.information(self, 'Done!', 'Done')
app = QApplication(sys.argv)
form = Dialog()
form.show()
app.exec_()
showGui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'show.ui'
#
# Created: Tue Apr 08 14:02:39 2014
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(379, 156)
self.nameEdit = QtGui.QLineEdit(Dialog)
self.nameEdit.setGeometry(QtCore.QRect(30, 40, 131, 31))
self.nameEdit.setText(_fromUtf8(""))
self.nameEdit.setObjectName(_fromUtf8("nameEdit"))
self.showButton = QtGui.QPushButton(Dialog)
self.showButton.setGeometry(QtCore.QRect(200, 40, 121, 31))
self.showButton.setObjectName(_fromUtf8("showButton"))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
Dialog.setTabOrder(self.showButton, self.nameEdit)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.nameEdit.setPlaceholderText(_translate("Dialog", "What is your name?", None))
self.showButton.setText(_tr
推荐答案
我想,作者不再是实际的,而是为了下一代:
您的功能开始了因为你明确地调用它之前按下按钮:
I suppose, It is no longer actual for the author, but for next generations:
Your function starts before you press the button because you call it explicitly:
self.connect(self.showButton, SIGNAL( 'clicked()' ), self.processData())
可能你想写:
Probably, you wanted to write:
self.connect(self.showButton, SIGNAL( 'clicked()' ), self.processData)
这篇关于PyQT SIGNAL的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!