Hi,
I have a small database application that allows maintaining the member list of a sports club.
I have a form with QLineEdit's for the different fields. I have a QSqlTableModel to connect to the table. I use a QDataWidgetMapper to connect the linedits to the fields in the database.
Like this :
model->setTable("MemberList");
model->select();
mapper->setModel(model);
mapper->addMapping(ui->leFirstName, model->fieldIndex("FirstName"));
mapper->addMapping(ui->leSurName, model->fieldIndex("SurName"));
QSqlTableModel *model= new QSqlTableModel(this);
model->setTable("MemberList");
model->select();
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(ui->leFirstName, model->fieldIndex("FirstName"));
mapper->addMapping(ui->leSurName, model->fieldIndex("SurName"));
To copy to clipboard, switch view to plain text mode
I can move back and forward using the navigation methods of the mapper :
mapper->toNext();
mapper->setCurrentIndex( /* any number here */ );
}
mapper->toNext();
mapper->setCurrentIndex( /* any number here */ );
}
To copy to clipboard, switch view to plain text mode
But now I need to move to a specific record. For instance, the user can type a name in a filter box somewhere, and the corresponding record must be shown. (In reality I get a key value of the record when a member is selected in some other form in the application, and need to move to the record with that value in its 'MemberKey' field.)
Unfortunately the mapper or model have no methods for searching for a specific record.
I thought I could use setFilter() on the model, like below, but when I do this the program crashes.
model
->setFilter
( QString(" FirstName= 'Peter' ") );
model->setFilter( QString(" FirstName= 'Peter' ") );
To copy to clipboard, switch view to plain text mode
Does anyone know how to move to a specific record ? I have no idea of the index number of the record to show, so I cannot use setCurrentIndex().
Best regards,
Marc
Bookmarks