QSqlQueryModel を実装するときに、返された要素にアクセスする方法を理解できません。
QSqlQuery クエリを実行できることは知っています。
query.prepare("select * from database");
query.exec();
query.next();
qDebug() << "value in 0 is " << query.value(0).SomeFormat;
だから私は QSqlQueryModel でそのようなことをしたい(どうやらより良い方法です)..クエリを設定する場所で、私が持っている別の多くのボックスに値を出力できます。私がこれまでに持っているものは...
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();
私は初心者なので、誰かが助けてくれれば正しい方向に微調整していただければ幸いです。
グラントに感謝