Reputation: 89
I have used QT Designer to have two QLineEdit's to take input from the user. After the user enters the values , when the Enter button is clicked I need the buttons to pass the values to the disk_angles function.
How to pass two strings to a function via signals with the press of a button? Here is my code
class Maindialog(QMainWindow,diskgui.Ui_MainWindow):
pass_arguments = SIGNAL((str,),(str,))
def __init__(self,parent = None):
super(Maindialog,self).__init__(parent)
self.setupUi(self)
self.connect(self.Home,SIGNAL("clicked()"),self.home_commands)
self.connect(self.AutoFocus,SIGNAL("clicked()"),self.auto_focus)
self.Enter.clicked.connect(self.entervalues)
self.connect(self,SIGNAL("pass arguments"),self.Criterion_disk_angles)
def entervalues(self):
if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
self.RotationEdit = str(self.RotationEdit.text())
self.TiltEdit = str(self.TiltEdit.text())
self.pass_arguments.emit(self.RotationEdit,self.TiltEdit)
def disk_angles(self,rotation_angle, tilt_angle):
I have tried to pass tuples as input to the signal
pass_arguments = SIGNAL((str,),(str,))
but I get the error
pass_arguments = SIGNAL((str,),(str,))
TypeError: SIGNAL() takes exactly one argument (2 given)
Upvotes: 0
Views: 599
Reputation: 244311
In PyQt5 it is recommended to use the new style, In addition you are sending 2 tuples of place of one, here I show an example of a correct implementation.
import sys
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtWidgets import QApplication, QPushButton
class Widget(QObject):
sig = pyqtSignal((str, str))
def __init__(self, parent=None):
super(Widget, self).__init__(parent=parent)
self.sig.connect(self.printer)
def click(self):
self.sig.emit("hello", "bye")
def printer(self, text1, text2):
print(text1, text2)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QPushButton()
w1 = Widget()
w.clicked.connect(w1.click)
w.show()
sys.exit(app.exec_())
Upvotes: 1