0
votes

I am calling a function that is refreshing the Qcombobox when I change selected index and calls data from DB, and it also fills another Qlistwidget with the values listed in the DB where (some condition ) = the current value of the Qcombobox, here is the code :

def category_change():
    conn = sqlite3.connect('storage/container.db')
    conn.row_factory = lambda c, row: row[0]
    c = conn.cursor()
    c.execute("SELECT category_name FROM categories")
    category_all = ['', ]
    for items in c.fetchall():
        category_all.append(items)
    conn.close()
    self.comboBox.clear()
    self.comboBox.addItems(category_all)
    conn = sqlite3.connect('storage/container.db')
    conn.row_factory = lambda c, row: row[0]
    c = conn.cursor()
    itemn1 = self.comboBox.currentText()
    itemn = unicode(itemn1)
    c.execute("SELECT itemName FROM items WHERE itemCategory = ?", (itemn, ))
    item_all = c.fetchall()
    conn.close()
    self.listWidget.clear()
    for items in item_all:
        self.listWidget.addItem(items)

self.comboBox.currentIndexChanged.connect(category_change)

and I get this error :

Traceback (most recent call last):
  File "G:\Python\townoftech-warehouse\Warehouse.py", line 146, in category_change
    conn = sqlite3.connect('storage/container.db')
RuntimeError: maximum recursion depth exceeded while calling a Python object
[Finished in 8.0s]

More information:

I am also using the same way to autoload items into the combobox when is start the program:

def setupUi(self, mainWindow):
  mainWindow.setObjectName(_fromUtf8("mainWindow"))
  mainWindow.resize(1262, 698)
  icon = QtGui.QIcon()
  icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/wh.ico")), 
  QtGui.QIcon.Normal, QtGui.QIcon.Off)
  mainWindow.setWindowIcon(icon)
  mainWindow.setDockNestingEnabled(False)
  self.centralwidget = QtGui.QWidget(mainWindow)
  self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
  self.gridLayout = QtGui.QGridLayout(self.centralwidget)
  self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
  self.comboBox = QtGui.QComboBox(self.centralwidget)
  self.comboBox.setObjectName(_fromUtf8("comboBox"))
  self.gridLayout.addWidget(self.comboBox, 1, 0, 1, 1)
  conn = sqlite3.connect('storage/container.db')
  conn.row_factory = lambda c, row: row[0]
  c = conn.cursor()
  c.execute("SELECT category_name FROM categories")
  category_all = ['']
  for items in c.fetchall():
    category_all.append(items)
  conn.close()
  self.comboBox.clear()
  self.comboBox.addItems(category_all)
1
Can you show us a bigger sample of the traceback? I expect there'll be a repeating pattern of lines. - Alex Hall
yes I've used the same pattern in the function setupUi function to have the values in the combo box when I start the program, and I repeated it inside the function to refresh the values ( which is changing dynamically as the user uses the program) whenever a user tries to change the Combobox , here is a the code of the other code edited in the question - Ahmed Wagdi

1 Answers

1
votes

It looks as though your category_change function gets called in response to a change in the combo box, but it modifies the contents of the combo box. This is most likely leading to an infinite loop: whenever the function is called it causes another call to itself, and another, and another..