Python Forum
Need help adding a sql List to a combo box PyQt5
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help adding a sql List to a combo box PyQt5
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo PySimpleGUI FilesBrowse enable event to update value in combo SamLiu 2 4,456 Mar-15-2023, 12:49 PM
Last Post: SamLiu
  How to update the list of a combo box in a QTableView panoss 10 6,129 Feb-05-2022, 03:24 PM
Last Post: panoss
  Radio butto to enable/disable combo box in Tkinter cybertooth 5 5,404 Oct-09-2021, 07:30 AM
Last Post: cybertooth
  PyQt5 adding image thewolf 3 3,220 Feb-21-2021, 08:28 PM
Last Post: thewolf
  Referencing Combo Box MC2020 6 2,863 Feb-12-2020, 10:17 PM
Last Post: woooee
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,785 Apr-06-2019, 11:15 PM
Last Post: ZenWoR

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020