我编写了一个从数据库获取数据的方法。
def connect():
connection = pymssql.connect(".","sa", "1234","Deneme")
cursor = connection.cursor()
cursor.execute("select BolumAdi from BOLUMLER")
return cursor.fetchone() //problem is here
此方法从数据库中获取一个数据并使用它:
def main():
app = QtGui.QApplication(sys.argv)
edit = QtGui.QLineEdit()
list = connect()
completer = QtGui.QCompleter(list,edit)
edit.setWindowTitle("PyQT QLineEdit Auto Complete")
edit.setCompleter(completer)
edit.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
它运作良好。但是由于上述原因,这仅显示一个数据cursor.fetchone()
。当我更改此行时cursor.fetchall()
,我可以从数据库中获取所有数据,但这次引发和异常:
TypeError: arguments did not match any overloaded call:
QCompleter(QObject parent=None): argument 1 has unexpected type 'list'
QCompleter(QAbstractItemModel, QObject parent=None): argument 1 has unexpected type 'list'
QCompleter(list-of-str, QObject parent=None): argument 1 has unexpected type 'list'
那么问题是什么?