Reputation: 1366
My database:
My code:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("sqlite.db");
db.open();
QSqlQuery query;
query.exec("SELECT * from Expenses");
QSqlTableModel *model = new QSqlTableModel(0, db);
model->setTable("Expenses");
model->select();
How I can to get the value of TOTAL for "January 2014"? I.e. "1".
Upvotes: 2
Views: 6372
Reputation: 77
for example:
QSqlTableModel *userModel=new QSqlTableModel(this);
userModel->setTable("person");
userModel->select();
const int row=0;
qDebug()<<userModel->index(row,9).data().toInt();
Upvotes: 3
Reputation: 19122
http://doc.qt.io/qt-4.8/qsqltablemodel.html#details
QSqlQueryModel model;
model.setQuery("SELECT * FROM employee");
int salary = model.record(4).value("salary").toInt();
http://doc.qt.io/qt-4.8/qsqltablemodel-members.html
http://doc.qt.io/qt-4.8/qsqlquerymodel.html#record
http://doc.qt.io/qt-4.8/qsqltablemodel.html#rowCount
int second_record_total = model->record(1).value("total").toInt();
or
int row_count = model->rowCount();
int latest_total = model->record(row_count - 1).value("total").toInt();
Hope that helps.
Upvotes: 7