In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The main content of this article is to explain "what is the method of binding the Qt database and TreeView components". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of binding a Qt database to a TreeView component?"
We first take the TreeView component as an example to briefly introduce how to bind the component to data. First, we need to create a table and insert several test records, and run the following code to build the database and build the table.
# include # include void Init () {QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE"); db.setDatabaseName (". / lyshark.db"); if (! db.open ()) {std::cout treeView- > setModel (qryModel); and ui- > treeView- > setSelectionModel (theSelection); display the model in the TreeView component as follows:
# include "mainwindow.h" # include "ui_mainwindow.h" # include # include / / define data model pointer QSqlQueryModel * qryModel; / / data model QItemSelectionModel * theSelection; / / Select model QDataWidgetMapper * dataMapper; / / data interface mapping MainWindow::MainWindow (QWidget * parent): QMainWindow (parent), ui (new Ui::MainWindow) {ui- > setupUi (this) QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE"); db.setDatabaseName (". / lyshark.db"); if (! db.open ()) {std::cout lastError (). IsValid () {return;} / / set the TableView header data qryModel- > setHeaderData (0Q QT qryModel- horizontal, "ID"); qryModel- > setHeaderData (1Q QT QSQLITE horizontal, "Name") QryModel- > setHeaderData; / / bind data to the model theSelection=new QItemSelectionModel (qryModel); ui- > treeView- > setModel (qryModel); ui- > treeView- > setSelectionModel (theSelection); ui- > treeView- > setSelectionBehavior (QAbstractItemView::SelectRows);} MainWindow::~MainWindow () {delete ui;}
After running the code, the program fetches the result from the database and outputs it to the TreeView component:
At this point, I believe that you have a deeper understanding of "what is the method of binding C _ Qt database to TreeView components". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.