QComboBox deactivate automatic alphabetical sorting
-
Hey everyone !
I'm using a QComboBox like that :
while (query.next) { this->ui->comboBoxChoixTest->insertItem(0,query.value(0).toString()); } query.prepare("COMMIT"); query.exec(); this->ui->comboBoxChoixTest->insertItem(0,"Choisir un Test"); this->ui->comboBoxChoixTest->setCurrentText("Choisir un Test");
I insert all items to index 0 so they have to stay in the order that I added them.
BUT actually it seems like there is an automatic alphabetical sorting…
Is it possible to avoid this sorting ?
Thanks :)
-
The default insert policy is not set to alphabetic sorting so I assume you enabled it (e.g. in the designer) - therefore please provide a minimal, compilable example to reproduce the issue.
-
Please provide an example with your problem, this works fine for me:
int main(int argc, char **argv) { QApplication app(argc, argv); QComboBox cbx; cbx.insertItem(0, "A"); cbx.insertItem(0, "B"); cbx.show(); return app.exec(); }
-
Oh I found Something ! It comes from my queries…
query.prepare("BEGIN TRANSACTION"); query.exec(); query.prepare("SELECT Nom_Test FROM LISTE_TESTS"); query.exec(); while (query.next()) { cout << query.value(0).toString().toStdString() << endl; this->ui->comboBoxChoixTest->insertItem(0,query.value(0).toString()); } query.prepare("COMMIT"); query.exec();
My table "LISTE_TESTS" is in this order :
-TU1
-TU2
-TU0
-ok
-tu1
-tu0
-tu2But with the cout it return like that (alphabeticaly) :
TU0
TU1
TU2
ok
tu0
tu1
tu2Okay so the problem comes from the queries but I can't see what is it...
-
That's the reason why I wanted a minimal example from you...