how to represent contents of Qvector
-
Hello everyone, I have a struct of Qstrings(name age address) stored in a QVector and would like to show each name in a box/container/widget alphabetically top to bottom. Then be able click on a name and the additional info is then shown. Which is the best way to do this?
Thanks James
-
Hi,
Sounds rather like a job for a small SQLite database.
In any case, you can:
- Create a QAbstractTableModel on top of your vector
- Use a QDataWidgetMapper to show the relevent fields in a custom widget like shown in this example.
-
Thanks! I will read up on the example shown. Trying to do a really simple contacts app. Thought I could use the vector of structs for the data...
-
Then start directly with the database. It's clearly a better container and long term storage for that kind of data.
-
Thanks! I am trying to learn Qt and C++ - this project is an exercise so I can get a feel for Qt and using widgets layouts buttons etc. I won't be using it anger... That is the reason I am using a vector - it will only store maybe a 10 -12 items at most to check the other functionality I am trying to write.
-
Then building a model on top of it will also be an interesting exercice.
What you can do is to create your version with vector plus model on top and once you have that working, move to a database and you'll see that the change needed should be minimal.
-
@jamesmfarrow
If you implement theQAbstractTableModel
approach, you will also find that you can present a data grid of the rows & columns in your data for free, by just putting a QTableView on to view it :) -
Thanks everyone. I will read up on the examples that you have listed and see what I can come up with. No doubt I will be back when I get stuck :)