PDA

View Full Version : Database Master-Detail Entry Form



Phan Sin Tian
2nd February 2008, 12:15
HI,

I am new to QT and is learning QT 4.2.3 in order to do Database programming using QT4

I have read thro all the QtSql and managed to do all the following:-

1. connect to database
2. add, delete database from database
3. create model on the database using QSqlTableModel and view it via QTableView
4. Access database data using QSqlquery for validation check

However, all the above is being done on a single table.

I want to do master details database access such as empoyee [header] and address [details]. I know i need to use QSqlrelation, however i notice that all those still talk about single table. Can any one help me on this but showing me how to go about doing master - detail database accesss such as sales invoices screen [customer ->master ] and items sold [at details].

Thanks in advance

:rolleyes:
Phan Sin Tian

jacek
2nd February 2008, 13:04
You need two table views, two models and a piece of code to connect them.

Few helpful methods:
QItemSelectionModel::currentRowChanged()
QAbstractItemView::selectionModel()
QSqlTableModel::setFilter()

Phan Sin Tian
2nd February 2008, 17:51
Hi, Jacek,

Thank you for your advice, do you have any sample with you so that i can see how you do it , Don mind if you can send me some sample.

Thanks

Phan Sin Tian
2nd February 2008, 23:47
I have also read about QDataWidgetMapper, do i need to make use of this as well for Master Detail Screen?

Regards

Phan Sin Tian:rolleyes:

jacek
3rd February 2008, 14:31
I have also read about QDataWidgetMapper, do i need to make use of this as well for Master Detail Screen?
You can, but you don't have to. All depends on the way you want to display data. QDataWidgetMapper is helpful if you display a single record in a form, instead of QTableView or similar widget.