I am having trouble understanding how i access the returned elements when i implement a QSqlQueryModel.
I know that you can do QSqlQuery query;
query.prepare("select * from database");
query.exec();
query.next();
qDebug() << "value in 0 is " << query.value(0).SomeFormat;
So i want to do something like that with QSqlQueryModel (apparently the better way to go).. where i set the query, then i can output the values to another lot of boxes i have. what i have so far is...
QSqlQuery selectAllUserFields;
selectAllUserFields.prepare(QString("SELECT * from %1 WHERE %2=:firstName and %3=:lastName;")
.arg(dbase::c_userTableName)
.arg(dbase::c_colUserFirstName)
.arg(dbase::c_colUserSecondName));
// finds the index of the current selection, so we can select the row
QModelIndexList tableIndex = m_ui->populatedUserBox->selectionModel()->selection().indexes();
QString firstName = tableIndex.at(0).data().toString();
QString lastName = tableIndex.at(1).data().toString();
QSqlQueryModel dbUsers;
dbUsers.setQuery(selectAllUserFields);
qDebug() << "DEBUG: {temp} " << dbUsers.record(0).value(0).toString();
I am beginnerish, so would appreciate a nudge in the right direction if anyone could assist.
Thanks Grant