|
|
Hi,
Heiko Steindl wrote:
I want to make a dialog-based application in Qt, which is populated with
data from a database.
There should be many dialogs with different records and underlying sql
tables. (with different fields).
Does anyone has an idea, how to make this the best way ?
Should I subclass QSqlQueryModel and add write support there and
subclass it for every dialog, to work with the different sql tables?
The form should be record based, with forward-rewind funktions, with
many Linedits, comboboxes and other widgets.
Should I sublcass a class from Qt's Views or should I better use
QDataMapper ?
Which Model/View is the best for this to subclass ?
Or should I create a new model and/or view, which I can sublcass for
every dialog?
I would be inclined to do the following:
- use QSqlTableModel or QSqlRelationalTableModel to give you a writable
model linked to your database
- use QDataWidgetMapper to provide the mechanism for tying a
QAbstractItemModel subclass to a bunch of widgets
- create your appropriate pieces of UI in designer
- create a container for the pieces of UI that will give an interface to
QDataWidgetMapper's toFirst(), toNext(), toPrevious(), toLast() etc.
Then, you need to come up with a scheme to allow the appropriate widgets
in the UI to be connected to the QDataWidgetMapper. Given Qt's good
introspection capability, I would (in designer) given the appropriate
widgets an object name that can easily be used be used with
QDataWidgetMapper e.g. input_1, input_2 and so on. You could then find
the appropriate widget with e.g. QObject::findChildren< QWidget* >(
"input_1" ) (you can see I'm leaning towards doing this all dynamically...)
Finally, I guess you can either write some classes to stick it all
together i.e. creating the model from a table name, aggregate the
generated data structure output by uic, ... or do it all dynamically by
loading the .ui files with QUiLoader and providing some kind of e.g. XML
file to map between tables, columns in the tables and the widgets in the
.ui files.
I'm sure there are some issues I've overlooked, but I hope that helps
you start!
Tim
----------------------------------------------------------------------
dr. t. dewhirst [t] +44 (0)1738 450 465
director [w] www.bugless.co.uk
bugless software development ltd.
[a] algo business centre, glenearn road, perth, PH2 0NJ
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|