Why is it invalid using value() of QSqlRecord?
-
QSqlTableModel *tblModel = (QSqlTableModel*)ui->tableView->model(); tblModel->setTable("TableTest"); QSqlRecord rec = tblModel->record(ui->tableView->currentIndex().row()); QVariant var; if(!rec.isEmpty()) { var = rec.value(0); }
Although rec is not empty, var is always invalid.
Why?
-
How do you use var?
You might have to use one of those methods e.g. toDouble(). -
Before using toDouble or other methods, var should be valid. But it is always invalid in fact.
I tried using toInt and toString, and the result was always 0.
-
@CoderJeff said:
QSqlRecord rec = tblModel->record(ui->tableView->currentIndex().row());
What is the value of
ui->tableView->currentIndex().row()
?