Solved Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox
-
self.query = QSqlQuery("SELECT name FROM test_table") self.comboBox = QComboBox(self) self.comboBox.currentIndexChanged.connect(self.selectionchange) # while(self.query.next()): self.comboBox.addItem(self.query.value(0).toString()) # def selectionchange(self): for count in range(self.comboBox.count()): print self.comboBox.itemText(count) self.show()
Edit by VRonin: in python indentation is essential. use ``` at the beginning and end of your code to highlight it
-
Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox
Yes, this is the behaviour you coded. what did you want to achieve instead?
-
@VRonin everytime i choose a name i only want it to display what i choose eg. like this if i choose "gelo" the chosen name will only appear not all of the name in my query it happens when i choose "gelo" all of the names appears
-
@VRonin i think the problem is in the while loop
-
@Gelo
Hi its not a bug or problem ?
You ask it to to do so.self.query = QSqlQuery("SELECT name FROM test_table") // get all names from table
FOR ALL NAMES IN TABLE
ADD TO COMBOBOX EACH OF THEMwhile(self.query.next()): self.comboBox.addItem(self.query.value(0).toString())
So its very unclear how you want it to work.
- i choose a name i only want it to display what i choose
So if combox is NOT to have all the names, how can u then choose in the first place.
If u mean like this
List is
A
B
CYou choose B
The list is cleared and now ONLY contains BBut then u cant reselect a new one, say A.
So i dont get your structure or use case.
Unless its oK that user cant select new after first selection. - i choose a name i only want it to display what i choose
-
for count in range(self.comboBox.count()):
print self.comboBox.itemText(count)for count in range(self.comboBox.count()): print self.comboBox.itemText(count)
this prints all the items
print self.comboBox.itemText(self.comboBox.currentIndex())
prints just the current
-
@VRonin Thanks men already solve the problem :)