![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QSqlForm class creates and manages data entry forms tied to SQL databases. More...
#include <qsqlform.h>
Inherits QObject.
The QSqlForm class creates and manages data entry forms tied to SQL databases.
Typical use of a QSqlForm consists of the following steps:
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.
Some sample code to initialize a form successfully:
QLineEdit myEditor( this ); QSqlForm myForm( this ); QSqlCursor myCursor( "mytable" ); // Execute a query to make the cursor valid myCursor.select(); // Move the cursor to a valid record (the first record) myCursor.next(); // Set the form's record pointer to the cursor's edit buffer (which // contains the current record's values) myForm.setRecord( myCursor.primeUpdate() ); // Insert a field into the form that uses myEditor to edit the // field 'somefield' in 'mytable' myForm.insert( &myEditor, "somefield" ); // Update myEditor with the value from the mapped database field myForm.readFields(); ... // Let the user edit the form ... // Update the database myForm.writeFields(); // Update the cursor's edit buffer from the form myCursor.update(); // Update the database from the cursor's buffer
If you want to use custom editors for displaying/editing data fields, you need to install a custom QSqlPropertyMap. The form uses this object to get or set the value of a widget.
Note that Qt Designer provides a visual means of creating data-aware forms.
See also installPropertyMap() and QSqlPropertyMap.
Constructs a QSqlForm with parent parent and name name.
Removes every widget, and the fields they're mapped to, from the form.
Clears the values in all the widgets, and the fields they are mapped to, in the form. If nullify is TRUE (the default is FALSE), each field is also set to null.
Returns the number of widgets in the form.
Returns the widget that field field is mapped to.
See also setRecord().
Examples: sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
Insert a widget, and the field it is to be mapped to, into the form.
See also installEditorFactory().
Example: sql/overview/custom1/main.cpp.
Update the widget widget with the value from the SQL field it is mapped to. Nothing happens if no SQL field is mapped to the widget.
Update the widgets in the form with current values from the SQL fields they are mapped to.
Examples: sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
Removes field from the form.
See also readFields() and writeFields().
Examples: sql/overview/custom1/main.cpp, sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
Returns the i 'th widget in the form. Useful for traversing the widgets in the form.
Returns the SQL field that widget widget is mapped to.
Update the SQL field with the value from the widget it is mapped to. Nothing happens if no SQL field is mapped to the widget.
Update 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 insert, update or del as appropriate.
Example: sql/overview/form2/main.cpp.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta2
|