Important: Please read the Qt Code of Conduct -

qt sqllite how to retrive a single value from database

  • i am using sqlllite with qt 5.9,currently i am try to fetch a single value from from sqllite database. i have checked the query in sqlite browser(3rd party tool) and the query is successful and single record as requested.
    But when i execute same query in qt and try to copy the value in string by following
    QString localData = dkv.value(0).toString();
    I have tried while( method also but not sure how to point the data at right index when i tried to use; to find out current position of cursor in database.

    So please suggest me how to get a single value from database by query execution and copy that value to string

  • can you share ur query & code snippet

  • Lifetime Qt Champion


    It should look like:

    QSqlQuery query("My SELECT QUERY");
    if ( {
    QString localData = query.value(0).toString();
    // rest of your code
    } else {
    qDebug() << "Nothing returned";

Log in to reply