RuntimeError:在运行sqlite3时调用Python对象时超出了最大递归深度

时间:2018-03-24 21:09:28

标签: python pyqt

当我更改所选索引并从DB调用数据时,我正在调用刷新Qcombobox的函数,并且它还使用DB中列出的值填充另一个Qlistwidget,其中(某些条件)= Qcombobox的当前值,这是代码:

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)

我收到此错误:

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]

更多信息:

启动程序时,我也使用相同的方法将项目自动加载到组合框中:

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 个答案:

答案 0 :(得分:0)

看起来你的category_change函数被调用以响应组合框中的更改,但它会修改组合框的内容。这很可能导致无限循环:无论何时调用该函数,它都会导致另一个调用自身,另一个调用,另一个调用...