Python Forum

Full Version: Need help adding a sql List to a combo box PyQt5
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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 pmList
To make sure your variable is a list, you may verify the output of print(type(self.pm_Combo)) before the call to addItems.