Question regarding to software modeling..
-
Hi, first of all, excuse me if this is not an specific Qt's question...
I´m working with Qt5 on a desktop application using sqlite... The application basically registerers a user into DB using a GUI form.. each field accepts a QString object.
My question is regarding to the model (or application flow).
I´m not sure how important is to create an User class that stores all user's field:class User{ QString name; int age; QString telephone; QString rol; //other public stuffs and member functions ahead. };
In the form, I have the same line edit objects quantity as required.
I have two ways to make it:
- Pass the data field (QStrings) to a new User, and add this user to a vector or list (to get then in order in memory). so I locally work with that vector/list and before my program finishes I copy the data into DB..
or
- Pass the data field (QString) directly to DB using SQL commands (INSERT into MYTABLE.. etc...)
What should I use? I sincerely see no sense using Nº 1... but I find it more elegant.....
Any Tips?
thanks. -
Well, you could create methods that abstract how the data is fed to/from the db inside the class. That might be a way to support other destinations for this data rather than hard coding it for the database. It really depends upon what else you might do with the data.
-
@U7Development
Use Qt SQL model classes, https://doc.qt.io/qt-5/sql-model.html.QSqlTableModel
(https://doc.qt.io/qt-5/qsqltablemodel.html) will allow you to manipulate rows, including writing them back to the database either immediately or batching up several changes. By all means declare your own classes to wrap access to the table rows/columns.