Take the 2-minute tour ×

How can I get a specified record from a table and row? Example:

Here is a pseudo structure of the datebase (sqlite):

Row1 Row2 Row3
Line1 Line1 Line1
Line2 Line2 Line2
... ... ...

I want to use get a line record from the datebase via Qt. For example how can I get Row2->Line2 string?

I tried this:

db.setDatabaseName("db.db"); //Yes the name of datebase is db.db
   if (db.open())
    QSqlQuery soruAl("SELECT question FROM questions",db);
    soruAl.exec();soruAl.first(); //These line does not affect result "QSqlQuery::value: not positioned on a valid record". 
    qDebug() << soruAl.value(5).toString(); // Here I want to get the 5. line of the question row which is in questions table.
    qDebug() << "Error";

But only response I get from debugger is "QSqlQuery::value: not positioned on a valid record"

share|improve this question
Dup of stackoverflow.com/questions/9000123/… –  lpapp Oct 27 '13 at 1:36

1 Answer 1

You're doing it wrong. Here's the example of doing it right

Also I recommend you to read QtSqlQuery help carefully - it all described there. Great help is one of the strongest advantages of using Qt.

share|improve this answer

Your Answer


