-1

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:

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); 
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.
}
else
{
    qDebug() << "Error";
}

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

Mat
  • 202,337
  • 40
  • 393
  • 406

1 Answers1

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.

Community
  • 1
  • 1
Amartel
  • 4,248
  • 2
  • 15
  • 21