Need help adding a sql List to a combo box PyQt5 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Need help adding a sql List to a combo box PyQt5 (/thread-11659.html) |
Need help adding a sql List to a combo box PyQt5 - jimmyvegas29 - Jul-20-2018 So this has been frustrating me for to man hours, and i have no been able to find the answer in the google. Im trying to query my db to get a distinct list from a certain row, and then take list and populate a combobox with it. I keep getting this error: TypeError: addItems(self, Iterable[str]) here is the code in question. ######Combo Box 2 - PM's self.groupBox_2 = QtWidgets.QGroupBox(self.tab) self.groupBox_2.setGeometry(QtCore.QRect(10, 140, 191, 51)) self.groupBox_2.setObjectName("groupBox_2") self.comboBox_3 = QtWidgets.QComboBox(self.groupBox_2) self.comboBox_3.setGeometry(QtCore.QRect(10, 20, 171, 22)) self.comboBox_3.setObjectName("comboBox_3") self.comboBox_3.addItems(self.pm_Combo) def pm_Combo(self): conn = sqlite3.connect('testdb.db') c = conn.cursor() c.execute("SELECT DISTINCT projectmanager FROM testtable2") pmList = c.fetchall() conn.commit() conn.close()indention is not correct since im just copying the relevant parts of the code Any help would be greatly appreciated, i feel like its something so simple. RE: Need help adding a sql List to a combo box PyQt5 - Alfalfa - Jul-20-2018 addItems takes a list, but you are passing a function instead. Try: def pm_Combo(self): conn = sqlite3.connect('testdb.db') c = conn.cursor() c.execute("SELECT DISTINCT projectmanager FROM testtable2") pmList = c.fetchall() conn.commit() conn.close() return pmListTo make sure your variable is a list, you may verify the output of print(type(self.pm_Combo)) before the call to addItems. |