Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

Q3SqlForm Class

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

Header:#include <Q3SqlForm>
Inherits:QObject

Public Functions

Q3SqlForm(QObject * parent = 0)
~Q3SqlForm()
intcount() const
QWidget *fieldToWidget(QSqlField * field) const
virtual voidinsert(QWidget * widget, const QString & field)
voidinstallPropertyMap(Q3SqlPropertyMap * pmap)
virtual voidremove(const QString & field)
virtual voidsetRecord(QSqlRecord * buf)
QWidget *widget(int i) const
QSqlField *widgetToField(QWidget * widget) const
  • 29 public functions inherited fromQObject

Public Slots

virtual voidclear()
virtual voidclearValues()
virtual voidreadField(QWidget * widget)
virtual voidreadFields()
virtual voidwriteField(QWidget * widget)
virtual voidwriteFields()
  • 1 public slot inherited fromQObject

Protected Functions

virtual voidinsert(QWidget * widget, QSqlField * field)
virtual voidremove(QWidget * widget)
  • 8 protected functions inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 signal inherited fromQObject
  • 7 static public members inherited fromQObject

Detailed Description

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

Typical use of aQ3SqlForm consists of the following steps:

  • Create the widgets you want to appear in the form.
  • Create a cursor and navigate to the record to be edited.
  • Create theQ3SqlForm.
  • Set the form's record buffer to the cursor's update buffer.
  • Insert each widget and the field it is to edit into the form.
  • UsereadFields() to update the editor widgets with values from the database's fields.
  • Display the form and let the user edit values etc.
  • UsewriteFields() to update the database's field values with the values in the editor widgets.

Note that aQ3SqlForm does not access the database directly, but most often via QSqlFields which are part of aQ3SqlCursor. AQ3SqlCursor::insert(),Q3SqlCursor::update() orQ3SqlCursor::del() call is needed to actually write values to the database.

Some sample code to initialize a form successfully:

QLineEdit  myEditor(this);Q3SqlForm   myForm(this);Q3SqlCursor myCursor("mytable");// Execute a query to make the cursor validmyCursor.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 fieldmyForm.readFields();...// Let the user edit the form...// Update the databasemyForm.writeFields();// Update the cursor's edit buffer from the formmyCursor.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 customQ3SqlPropertyMap. The form uses this object to get or set the value of a widget.

See alsoinstallPropertyMap() andQ3SqlPropertyMap.

Member Function Documentation

Q3SqlForm::Q3SqlForm(QObject * parent = 0)

Constructs aQ3SqlForm with parentparent.

Q3SqlForm::~Q3SqlForm()

Destroys the object and frees any allocated resources.

[virtual slot]void Q3SqlForm::clear()

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

[virtual slot]void Q3SqlForm::clearValues()

Clears the values in all the widgets, and the fields they are mapped to, in the form, and sets them to NULL.

int Q3SqlForm::count() const

Returns the number of widgets in the form.

QWidget * Q3SqlForm::fieldToWidget(QSqlField * field) const

Returns the widget that fieldfield is mapped to.

[virtual]void Q3SqlForm::insert(QWidget * widget, constQString & field)

Inserts awidget, and the name of thefield it is to be mapped to, into the form. To actually associate inserted widgets with an edit buffer, usesetRecord().

See alsosetRecord().

[virtual protected]void Q3SqlForm::insert(QWidget * widget,QSqlField * field)

This is an overloaded function.

Inserts awidget, and thefield it is to be mapped to, into the form.

void Q3SqlForm::installPropertyMap(Q3SqlPropertyMap * pmap)

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

Q3SqlForm takes ownership ofpmap, sopmap is deleted whenQ3SqlForm goes out of scope.

See alsoQ3DataTable::installEditorFactory().

[virtual slot]void Q3SqlForm::readField(QWidget * widget)

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

[virtual slot]void Q3SqlForm::readFields()

Updates the widgets in the form with current values from the SQL fields they are mapped to.

[virtual protected]void Q3SqlForm::remove(QWidget * widget)

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

[virtual]void Q3SqlForm::remove(constQString & field)

This is an overloaded function.

Removesfield from the form.

[virtual]void Q3SqlForm::setRecord(QSqlRecord * buf)

Setsbuf as the record buffer for the form. To force the display of the data frombuf, usereadFields().

See alsoreadFields() andwriteFields().

QWidget * Q3SqlForm::widget(int i) const

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

QSqlField * Q3SqlForm::widgetToField(QWidget * widget) const

Returns the SQL field that widgetwidget is mapped to.

[virtual slot]void Q3SqlForm::writeField(QWidget * widget)

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

[virtual slot]void Q3SqlForm::writeFields()

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, useQ3SqlCursor::insert(),Q3SqlCursor::update() orQ3SqlCursor::del() as appropriate.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp