Display Values from database to Qcombobox
-
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.
-
@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.