Struct, Class or Enum? What should I use to store data from sql query and display to QLineEdit
-
Hello all,
I have a QListWidget where I can select from a variety of names. When I click on a name in the QListWidget, a database query is made and further data such as name, genus, species, synonyms etc. is loaded. This data should be displayed in different QLineEdits + a QListWidget + a QPlainTextEdit, edited if necessary and saved back to the database.What is the best way to proceed with something like this? Should I create a class, a struct or rather use an enum to store the data and integrate it into the individual fields? How do you do something like this?
About the database:
Should I rather make a query where the data is fetched from several tables or query each table separately? Which is the better approach?As background still: The data must be able to be changed only from the data base into the GUI, there and be pushed again back into the data base.
I had already thought about the following struct, but would like to know from you what the best method is.
Here my struct
struct Mushroom{ int id; QString fullname; QString genus; QString kind; QString family; QString order; QStringList germanNames; QStringList synonyms; QString redlist; QString notes; };
Thanks for your help
Gabber -
Hi,
You should check QDataWidgetMapper.
-
Hi
Its a requirement that the data be shown in LineEdits etc ?
Im asking as Qt can show a table from DB with full edits in just a few lines of code.
https://doc.qt.io/qt-5/qsqltablemodel.html
https://doc.qt.io/qt-5/qsqlrelationaltablemodel.html#detailsIf yes, it must, then QDataWidgetMapper is the way to go as @SGaist suggests.
-
Thanks for the tip. It works wonderfully with the mapper (at least the display of the content) change and reinsert into the database I still have to implement. If it does not work, I would contact you again if necessary.
Should I mark the thread as solved or only when I have implemented the change and insert also, in case of possible queries?
-
Thanks for the tip. It works wonderfully with the mapper (at least the display of the content) change and reinsert into the database I still have to implement. If it does not work, I would contact you again if necessary.
Should I mark the thread as solved or only when I have implemented the change and insert also, in case of possible queries?
@Gabber
Hi
It's fine to close it and then just open another one in case you got new questions.
This will keep the posts shorter and easier for newcomers to look at if they search for solutions.