Line 8 and 9 in your first code snippet make no sense where you have put them in the construction code.
I have commented in your second code snippet:
void MainWindow
::fory3(QModelIndex index
) // I assume this is a typing error fory3 or for3? // ^^^^^ this is an index in the proxy model
{
// Before you can use the index against the source QSqlTableModel you need to map it
QModelIndex srcIndex
= filterModel
->mapToSource
(index
);
QSqlRecord record
= model
->record
(srcIndex.
row());
QString name
= record.
value("artist").
toString();
QString jobv
= record.
value("job").
toString();
QString person2serial
= record.
value("serialno").
toString();
void MainWindow::fory3(QModelIndex index) // I assume this is a typing error fory3 or for3?
// ^^^^^ this is an index in the proxy model
{
// Before you can use the index against the source QSqlTableModel you need to map it
QModelIndex srcIndex = filterModel->mapToSource(index);
QSqlRecord record = model->record(srcIndex.row());
QString name = record.value("artist").toString();
QString jobv = record.value("job").toString();
QString person2serial= record.value("serialno").toString();
To copy to clipboard, switch view to plain text mode
However, you don't need to worry about the layering of models if you use the Model/View interface to access the data
{
int row = index.row();
QString name
= index.
sibling(row, nameColumn
).
data().
toString();
QString jobv
= index.
sibling(row, jobvColumn
).
data().
toString();
QString person2serial
= index.
sibling(row, serialnoColumn
).
data().
toString()
void MainWindow::for3(QModelIndex index)
{
int row = index.row();
QString name = index.sibling(row, nameColumn).data().toString();
QString jobv = index.sibling(row, jobvColumn).data().toString();
QString person2serial= index.sibling(row, serialnoColumn).data().toString()
To copy to clipboard, switch view to plain text mode
Bookmarks