-1

I have a table in pyqt5 and when I modify a cell I call a method(changeIcon), inside this method I use an if statement to check which column has been changed and based on the column I change some items, everytime I modify the column 3 and 4 it returns me this error:

Traceback (most recent call last):
File "c:\FOLDER\App.py", line 291, in Change_method
RecursionError

This is the code :

def tabledata(self)
    .....
    self.tabella_registrazioni.itemChanged.connect(self.changeIcon) 
    .....

def changeIcon(self, item):
    row = item.row()
    col = item.column()
    custcode = self.tabella_registrazioni.item(row, 3).text()
    custname = self.tabella_registrazioni.item(row, 4).text()
    if col == 3 :
        if not custcode.isspace() and custcode != " " and custcode != "":
            cname = d.execute("SELECT 1 FROM CODES WHERE ANCODICE = ?", (custcode)).fetchone()[0]
            if cname != None:
                self.tabella_registrazioni.setItem(row, 4, QtWidgets.QTableWidgetItem(str(cname)))
    if col == 4 :
        if not custname.isspace() and custname != " " and custname != "":
            ccode = d.execute("SELECT 2 FROM CODES WHERE ANDESCRI = ?", (custname)).fetchone()[0]
            if ccode != None:
                self.tabella_registrazioni.setItem(row, 3, QtWidgets.QTableWidgetItem(str(ccode)))  
8
  • 1
    Please include the full traceback error. Commented Jul 6, 2022 at 8:38
  • I did it but it doesn't give any additional information Commented Jul 6, 2022 at 8:40
  • What is the Change_method? Commented Jul 6, 2022 at 8:42
  • it's the name of the function, this if statements is inside the Change_method and line 291 it's the line that starts with cname = d.execute("..... Commented Jul 6, 2022 at 8:45
  • Ensure that you do get the full traceback, by running the code in a prompt or terminal. Also, please provide a minimal reproducible example. Commented Jul 6, 2022 at 9:01

1 Answer 1

2

I find out why it returned that error , everytime I change the item of the column 3 or 4 it gives a signal and calls this method, so when I try to change the column 4 automatically the column 3 changes based on column 4, but when the columns 3 changes the column 4 changes as well, this for infinte times. The solution was to block signals before setting the item and to enable them after I set the item :

self.tabella_registrazioni.blockSignals(True)
self.tabella_registrazioni.setItem(row, 3, QtWidgets.QTableWidgetItem(str(ccode)))
self.tabella_registrazioni.blockSignals(False)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.