QTreeWidget + SQL
-
Hello! I need to work in qtreewidget(or qtreeview) with sql quieries. How to do that? Also, I need to make hierarchical model in this widget with main sql quieries and the requests of the second and third order.
Like that:
England
--- London
------ East Café
USA
--- New York
France -
Hi and welcome to devnet,
What do you mean by second and third order ?
-
So you'd like to re-run a query for each entry and populate the tree widget ?
Sounds pretty expensive.
What are the relation between your different entries ?
-
So you'd like to re-run a query for each entry and populate the tree widget ?
Sounds pretty expensive.
What are the relation between your different entries ?
@SGaist No, I don't want anything about that, because I just want to solve the problem. Every variant will be good.
In my database there is 3 tables: country, city, streets. I want that:
In QTreeWidget you see the list of countries, then if you will click on some country, you will see cities, and if you'll click on city you will see streets. Typical situation in this widget. But I don't know how to do that. -
Ok, then the most straight forward is to build your own model with its content based on the result of your queries.
-
Ok, then the most straight forward is to build your own model with its content based on the result of your queries.
-
QStandardItemModel's documentation details show how to build a table or a tree model. Based on that you can build it using your query results. So you'll start by querying the content of your Country table, then while you loop on the result you'll make a query for the cities of that country and again in that loop get the places.
Note that this is the quick, simple and not optimized way to extract your data.