18.3.  Database Models

[ fromfile: database.xml id: dbmodels ]

Figure 18.2 shows the concrete model classes for connecting to a QTableView.

Figure 18.2.  Sql Table Models

Sql Table Models

If you want to show a table that was created after calling Example 18.4, it takes five lines of code with the QSqlTableModel.

Example 18.7. src/libs/tests/testsqlmetadata/testsqlmetadata.cpp

[ . . . . ]

void TestSqlMetaData::showTable() {
    QSqlTableModel model;
    model.setTable("MetaData");
    model.select();
    QTableView *view = new QTableView;
    view->setModel(&model);
    view->setItemDelegate(new SimpleDelegate(view));
    

The testcase, excerpted in Example 18.7 scans a directory of your choice, as set by an environment variable, TESTTRACKS, and adds metadata for each mp3 file found to the table model. It is included in the source tarball in from dist.