Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQSqlForm Class Reference
[sql module]

The TQSqlForm class creates and manages data entry forms tied to SQL databases. More...

#include <tqsqlform.h>

Inherits TQObject.

List of all member functions.

Public Members

Public Slots

Protected Members


Detailed Description

The TQSqlForm class creates and manages data entry forms tied to SQL databases.

Typical use of a TQSqlForm consists of the following steps:

Note that a TQSqlForm does not access the database directly, but most often via TQSqlFields which are part of a TQSqlCursor. A TQSqlCursor::insert(), TQSqlCursor::update() or TQSqlCursor::del() call is needed to actually write values to the database.

Some sample code to initialize a form successfully:

    TQLineEdit  myEditor( this );
    TQSqlForm   myForm( this );
    TQSqlCursor 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 and editing data fields, you must install a custom TQSqlPropertyMap. The form uses this object to get or set the value of a widget.

Note that TQt Designer provides a visual means of creating data-aware forms.

See also installPropertyMap(), TQSqlPropertyMap, and Database Classes.


Member Function Documentation

TQSqlForm::TQSqlForm ( TQObject * parent = 0, const char * name = 0 )

Constructs a TQSqlForm with parent parent and called name.

TQSqlForm::~TQSqlForm ()

Destroys the object and frees any allocated resources.

void TQSqlForm::clear () [virtual slot]

Removes every widget, and the fields they're mapped to, from the form.

void TQSqlForm::clearValues ( bool nullify = FALSE ) [virtual slot]

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.

uint TQSqlForm::count () const

Returns the number of widgets in the form.

TQWidget * TQSqlForm::fieldToWidget ( TQSqlField * field ) const

Returns the widget that field field is mapped to.

void TQSqlForm::insert ( TQWidget * widget, const TQString & field ) [virtual]

Inserts a widget, and the name of the field it is to be mapped to, into the form. To actually associate inserted widgets with an edit buffer, use setRecord().

See also setRecord().

Examples: sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.

void TQSqlForm::insert ( TQWidget * widget, TQSqlField * field ) [virtual protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a widget, and the field it is to be mapped to, into the form.

void TQSqlForm::installPropertyMap ( TQSqlPropertyMap * pmap )

Installs a custom TQSqlPropertyMap. This is useful if you plan to create your own custom editor widgets.

TQSqlForm takes ownership of pmap, so pmap is deleted when TQSqlForm goes out of scope.

See also TQDataTable::installEditorFactory().

Example: sql/overview/custom1/main.cpp.

void TQSqlForm::readField ( TQWidget * widget ) [virtual slot]

Updates 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.

void TQSqlForm::readFields () [virtual slot]

Updates 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.

void TQSqlForm::remove ( TQWidget * widget ) [virtual protected]

Removes a widget, and hence the field it's mapped to, from the form.

void TQSqlForm::remove ( const TQString & field ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Removes field from the form.

void TQSqlForm::setRecord ( TQSqlRecord * buf ) [virtual]

Sets buf as the record buffer for the form. To force the display of the data from buf, use readFields().

See also readFields() and writeFields().

Examples: sql/overview/custom1/main.cpp, sql/overview/form1/main.cpp, and sql/overview/form2/main.cpp.

TQWidget * TQSqlForm::widget ( uint i ) const

Returns the i-th widget in the form. Useful for traversing the widgets in the form.

TQSqlField * TQSqlForm::widgetToField ( TQWidget * widget ) const

Returns the SQL field that widget widget is mapped to.

void TQSqlForm::writeField ( TQWidget * widget ) [virtual slot]

Updates the SQL field with the value from the widget it is mapped to. Nothing happens if no SQL field is mapped to the widget.

void TQSqlForm::writeFields () [virtual slot]

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 TQSqlCursor::insert(), TQSqlCursor::update() or TQSqlCursor::del() as appropriate.

Example: sql/overview/form2/main.cpp.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8