I have the following function to fill a comboBox with the data entered in the form by the user, this works correctly.
def onTextChanged(self, text):
if text:
sql = ("SELECT sec.Nombre as Seccion,sec,idSeccion FROM [Lote] lot \
inner join [Seccion] sec on sec.idInforme = lot.idInforme \
Where idLote = '%s'") % \
(self.dlg.lote.text())
cursorLista.execute(sql)
self.dlg.comboBox.clear()
self.dlg.comboBox.addItems([str(x[0]) for x in cursorLista])
Then I call him from
self.dlg.lote.textChanged.connect(self.onTextChanged)
result = self.dlg.exec_()
The problem is that now I need to obtain the id of the Section that was selected in the comboBox and store it in a variable, how can I obtain it since in the query I am bringing all the idSection for that Lot.
QComboBox allows you to store additional information associated with each item using
setItemData()
, in your case you could make the idSection, and retrieve it usingitemData()
: