Reference Variables

Table of contents:

Database View

A database view is not very different from an ordinary playlist view except that it permits you to see a larger collection of songs, organized in different ways to aid in the selection process.

Typically, a database view can be achieved with a table, a tree of lists, or a table of lists. The simplest way is to use the QTableView and then connect it to a model that represents the data.

Qt, when it is built with the correct options, can access SQL databases, so that we can use QSqlTableModel. Using this with the regular QTableView gives you an editable tabular view of a database table. The database view shown in Figure 25.11 looks like an ordinary table view, because it is! It's just hooked up to a database model.

Figure 25.11. QTableView of a database

Example 25.5. ../src/libs/filetagger/filetagger.sql

create database mp3db;
use mp3db;
grant all on mp3db.* to 'mp3db'@'localhost' identified by 'mp3dbpw';
grant all on mp3db.* to mp3db identified by 'mp3dbpw';

drop table FileTagger;
 Artist varchar(100),
 TrackTitle varchar(100),
 AlbumTitle varchar(100),
 TrackNumber varchar(10),
 Genre varchar(20),
 Comment varchar(200),
 Preference varchar(20),
 Filename varchar(200),
 PRIMARY KEY(Filename),

Example 25.5 contains the SQL table definition, and Figure 25.12 contains a suggested initial design for the model.


Extend the Mp3TableModel so that it derives from PlayListModel and fits into your larger program.


Write a Library menu with an option to "import songs into library," which imports the songs into the database and updates the view.

Figure 25.12. Database table model

Part I: Introduction to C++ and Qt 4

C++ Introduction


Introduction to Qt



Inheritance and Polymorphism

Part II: Higher-Level Programming


Introduction to Design Patterns


Generics and Containers

Qt GUI Widgets


Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments


MP3 Jukebox Assignments

An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268 © 2008-2020.
If you may any questions please contact us: