May 2019
Intermediate to advanced
542 pages
13h 37m
English
Populating data into a table widget manually seems like an awful chore; if you recall Chapter 5, Creating Data Interfaces with Model-View Classes, Qt provides us with model-view classes that do the boring work for us. We could subclass QAbstractTableModel and create a model that is populated from a SQL query, but fortunately, QtSql already provides this in the form of QSqlQueryModel.
As the name suggests, QSqlQueryModel is a table model that uses a SQL query for its data source. We'll use one to create our coffee products list, like so:
coffees = qts.QSqlQueryModel() coffees.setQuery( "SELECT id, coffee_brand, coffee_name AS coffee " "FROM coffees ORDER BY id")
After creating our model, we set its query property to a ...
Read now
Unlock full access