The QSqlForm class creates and manages data entry forms tied to SQL databases.
.PP
Typical use of a QSqlForm consists of the following steps:
.TP
Create the widgets you want to appear in the form.
.TP
Create a cursor and navigate to the record to be edited.
.TP
Create the QSqlForm.
.TP
Set the form's record buffer to the cursor's update buffer.
.TP
Insert each widget and the field it is to edit into the form.
.TP
Use readFields() to update the editor widgets with values from the database's fields.
.TP
Display the form and let the user edit values etc.
.TP
Use writeFields() to update the database's field values with the values in the editor widgets.
.PP
Note that a QSqlForm does not access the database directly, but most often via QSqlFields which are part of a QSqlCursor. A QSqlCursor::insert(), QSqlCursor::update() or QSqlCursor::del() call is needed to actually write values to the database.
.PP
Some sample code to initialize a form successfully:
.PP
.nf
.br
QLineEdit myEditor( this );
.br
QSqlForm myForm( this );
.br
QSqlCursor myCursor( "mytable" );
.br
.br
// Execute a query to make the cursor valid
.br
myCursor.select();
.br
// Move the cursor to a valid record (the first record)
.br
myCursor.next();
.br
// Set the form's record pointer to the cursor's edit buffer (which
.br
// contains the current record's values)
.br
myForm.setRecord( myCursor.primeUpdate() );
.br
.br
// Insert a field into the form that uses myEditor to edit the
.br
// field 'somefield' in 'mytable'
.br
myForm.insert( &myEditor, "somefield" );
.br
.br
// Update myEditor with the value from the mapped database field
.br
myForm.readFields();
.br
...
.br
// Let the user edit the form
.br
...
.br
// Update the database
.br
myForm.writeFields(); // Update the cursor's edit buffer from the form
.br
myCursor.update(); // Update the database from the cursor's buffer
.br
.fi
.PP
If you want to use custom editors for displaying and editing data fields, you must install a custom QSqlPropertyMap. The form uses this object to get or set the value of a widget.
.PP
Note that Qt Designer provides a visual means of creating data-aware forms.
.PP
See also installPropertyMap(), QSqlPropertyMap, and Database Classes.
Clears the values in all the widgets, and the fields they are mapped to, in the form. If \fInullify\fR is TRUE (the default is FALSE), each field is also set to NULL.
.SH "uint QSqlForm::count () const"
Returns the number of widgets in the form.
.SH "QWidget * QSqlForm::fieldToWidget ( QSqlField * field ) const"
Returns the widget that field \fIfield\fR is mapped to.
Inserts a \fIwidget\fR, and the name of the \fIfield\fR it is to be mapped to, into the form. To actually associate inserted widgets with an edit buffer, use setRecord().
.PP
See also setRecord().
.PP
Examples:
.)l sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
Updates the SQL fields with values from the widgets they are mapped to. To actually update the database with the contents of the record buffer, use QSqlCursor::insert(), QSqlCursor::update() or QSqlCursor::del() as appropriate.