Issue
i am using python and qt designer when i am working on my controller i have this error :
File "/home/sabri/Bureau/PycharmProjects/PFE/Controller/Cat.py", line 14, in init self.ui.AddBtn.connect(self.add) TypeError: arguments did not match any overloaded call: QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'instancemethod' QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'instancemethod' QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'instancemethod'
this is the first time i get this error , what's the problem ! and this is my code :
from PyQt4 import QtCore, QtGui
from PFE.Classes.categorie import Category
from PFE.Interfaces.Categorie import Ui_Categorie_2
class Window(QtGui.QDialog):
def __init__(self):
QtGui.QApplication.__init__(self)
self.ui = Ui_Categorie_2()
self.ui.setupUi(self)
self.ui.AddBtn.connect(self.add)
def add(self):
a = str(self.ui.textEdit.toPlainText())
b = str(self.ui.textEdit_2.toPlainText())
cat=Category(a, b)
cat.save_to_db()
print ("ajout avec success ")
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Solution
The way to connect a signal with its slot is the following:
{sender}.{signal}.connect({slot})
Considering that AddBtn
is a button and you want to use the clicked signal your code should be as follows:
self.ui.AddBtn.clicked.connect(self.add)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.