So, it is better to write a custom model for each view or just use regular widgets e.g. qTableWidget to present the data?
I don't know, it depends on the application. Maybe for your needs it will be just fine to use a simple table widget. I'm not a specialist on table view/model things, so maybe someone else will have some hints for you.
My point is, if you hardcode db access with queries you may find it inconvenient in some cases. For example, your version of "GetUser" method could be uncomfortable if we have to present user details in a labels or set of line edits for editing:
// here you can see 'GetUser' method name is not very self-explanatory
ui.label_name->setText(query.value("name").toString());
ui.label_address->setText(query.value("address").toString());
vs.
User user = db.GetUser(id);
ui.label_name->setText(user.name());
ui.label_address->setText(user.address());
// etc
// here you can see 'GetUser' method name is not very self-explanatory
QSqlQuery query = db.GetUser(id);
ui.label_name->setText(query.value("name").toString());
ui.label_address->setText(query.value("address").toString());
vs.
User user = db.GetUser(id);
ui.label_name->setText(user.name());
ui.label_address->setText(user.address());
// etc
To copy to clipboard, switch view to plain text mode
Bookmarks