I use this code.
model = new QSqlQueryModel(this);
model->setQuery("select id,parent,name from table");
tree = new QTreeView(this);
tree->setModel(model);
In TreeView displays table, but not tree. How to display tree?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, it wouldn’t return a tree as the QSqlQueryModel results in a flat table which is what comes out of the database.
You have two options for making it into a tree view, create your own model either through subclassing or just build a
QStandardItemModel, or use anQAbstractProxyModelto create the mapping between your QSqlQuery table result to your grouped tree data model.