3

I have a combobox on a QTDesigner QDialog form that I would like to fill with a the contents of a column in a CSV file. I invoke the call for the combo box and have the function built to pull the values from the CSV, but the combo box will not update with the information.

self.optStates.currentIndexChanged.connect(self.selectState)
def selectState(self):
    with open('States.csv') as csvDataFile:
        csvReader = csv.DictReader(csvDataFile, delimiter=',')
        states = []
        states.extend([row['state'] for row in csvReader if row['state']])

The other code has been omitted, but the rest of the dialog works fine.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
BTBean
  • 43
  • 5

1 Answers1

4

currentIndexChanged is a signal that is triggered when you choose an option of the QComboBox and since there is no item in your QComboBox it will never fire, besides there is no need to use it in this case. What you must do is fill it in the constructor using the addItems() method

def __init__(self, another_arguments):
    # 
    # some code
    # 
    with open('States.csv') as csvDataFile:
        csvReader = csv.DictReader(csvDataFile, delimiter=',')
        states = [row['state'] for row in csvReader if row['state']]
        self.optStates.addItems(states)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thanks! Worked like a charm. For some reason I had in it in a pyqtSlot() as well and needed to put it in the main __init__. Works like a champ now. – BTBean Jan 22 '18 at 03:33