Display Values from database to Qcombobox
-
wrote on 25 Apr 2020, 20:49 last edited by
Hi ! I'm a newbie with QT and c++, I have been trying to display values from Qcombobox from the Database, but no avail. I was wondering if someone can take a look and help me.
Here's a section of my codeQSqlQuery query;
query.prepare("SELECT rep FROM Auth");
query.exec();
query.first();
QString a= query.value(0).toString();
ui->nnid->addItem(a);Thank you
-
Hi and welcome to the forums.
If you dont get anything in combobox
then i guess the SqlQuery dont get any results ?update:
you could tryif ( ! query.first() )
qDebug() << "no record";QString a= query.value(0).toString();
ui->nnid->addItem(a);to see if it can position on first record.
-
wrote on 25 Apr 2020, 21:47 last edited by
Thank you for taking the time to answer me, however that did not work as well. I honestly don't know what I'm doing wrong, because apart from this, I already have a Crud working.
-
Thank you for taking the time to answer me, however that did not work as well. I honestly don't know what I'm doing wrong, because apart from this, I already have a Crud working.
Did it show "no record" ?
or what happens ?
While you are not checking return values, it does look ok.
-
wrote on 25 Apr 2020, 21:59 last edited by
Sorry I definitely forgot to mention that part.
no actually nothing showed up !!! -
wrote on 25 Apr 2020, 22:56 last edited by
actually nevermind, it worked ! thank you !!
-
@xayn13
Super :)For debugging help , its a good idea to do
QSqlQuery query; query.exec(QString("xxx"); if (query.next()) { // use it } else { qDebug() << "SqLite error:" << query.lastError().text() << ", SqLite error code:" << query.lastError().number(); }
as it does report good stuff in case of something up with the query.
-
wrote on 25 Apr 2020, 23:35 last edited by
that's more or less what I did !
Thank you though !!
1/9