[SOLVED]Fetch data from a sqlite database to a label

  • Hello, I'm new to Qt and and I'm trying to read data from a db to a label (actually I want that data on a combo box but if I get it to work on a label it shouldn't be hard to use that on the combo I think) so here's my code:


    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    bool db_ok = db.open();
    QSqlQuery query("SELECT SITE FROM MASTER");
    QString example = query.value(1).toString();

    Also can you recommend a book or an online course, the documentation is good but for things like this I struggle a little.

    Thank You.


    So i did this:

    QSqlQuery query("SELECT SITE FROM MASTER");
    while (query.next()){

    Because what I really want was to put the data on a combo box I use the combo and for a label the code will be:

    QSqlQuery query("SELECT SITE FROM MASTER");
    while (query.next()){

    Have in mind that using it this way only "stores" the current or last value read so that's why only works when use 0{query.value(0)}

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You never execute the request so you don't have any valid result.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.