1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/qt3support/sql/q3sqlform.cpp -->
7
<title>Qt 4.0: Q3SqlForm Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="annotated.html"><font color="#004faf">Annotated</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td>
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">Q3SqlForm Class Reference</h1>
21
<p>The Q3SqlForm class creates and manages data entry forms tied to SQL databases. <a href="#details">More...</a></p>
22
<pre>#include <Q3SqlForm></pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See the <a href="porting4.html">Porting Guide</a> for more information.</p>
23
<p>Part of the <a href="qt3support.html">Qt3Support</a> module.</p>
24
<p>Inherits <a href="qobject.html">QObject</a>.</p>
26
<li><a href="q3sqlform-members.html">List of all members, including inherited members</a></li>
28
<a name="public-functions"></a>
29
<h3>Public Functions</h3>
31
<li><div class="fn"/><b><a href="q3sqlform.html#Q3SqlForm">Q3SqlForm</a></b> ( QObject * <i>parent</i> = 0 )</li>
32
<li><div class="fn"/><b><a href="q3sqlform.html#dtor.Q3SqlForm">~Q3SqlForm</a></b> ()</li>
33
<li><div class="fn"/>int <b><a href="q3sqlform.html#count">count</a></b> () const</li>
34
<li><div class="fn"/>QWidget * <b><a href="q3sqlform.html#fieldToWidget">fieldToWidget</a></b> ( QSqlField * <i>field</i> ) const</li>
35
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#insert">insert</a></b> ( QWidget * <i>widget</i>, const QString & <i>field</i> )</li>
36
<li><div class="fn"/>void <b><a href="q3sqlform.html#installPropertyMap">installPropertyMap</a></b> ( Q3SqlPropertyMap * <i>pmap</i> )</li>
37
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#remove-2">remove</a></b> ( const QString & <i>field</i> )</li>
38
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#setRecord">setRecord</a></b> ( QSqlRecord * <i>buf</i> )</li>
39
<li><div class="fn"/>QWidget * <b><a href="q3sqlform.html#widget">widget</a></b> ( int <i>i</i> ) const</li>
40
<li><div class="fn"/>QSqlField * <b><a href="q3sqlform.html#widgetToField">widgetToField</a></b> ( QWidget * <i>widget</i> ) const</li>
43
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
45
<a name="public-slots"></a>
48
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#clear">clear</a></b> ()</li>
49
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#clearValues">clearValues</a></b> ()</li>
50
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#readField">readField</a></b> ( QWidget * <i>widget</i> )</li>
51
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#readFields">readFields</a></b> ()</li>
52
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#writeField">writeField</a></b> ( QWidget * <i>widget</i> )</li>
53
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#writeFields">writeFields</a></b> ()</li>
56
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
58
<a name="protected-functions"></a>
59
<h3>Protected Functions</h3>
61
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#insert-2">insert</a></b> ( QWidget * <i>widget</i>, QSqlField * <i>field</i> )</li>
62
<li><div class="fn"/>virtual void <b><a href="q3sqlform.html#remove">remove</a></b> ( QWidget * <i>widget</i> )</li>
65
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
67
<h3>Additional Inherited Members</h3>
69
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
70
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
71
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
73
<a name="details"></a>
75
<h2>Detailed Description</h2>
76
<p>The Q3SqlForm class creates and manages data entry forms tied to SQL databases.</p>
77
<p>Typical use of a Q3SqlForm consists of the following steps:</p>
79
<li>Create the widgets you want to appear in the form.</li>
80
<li>Create a cursor and navigate to the record to be edited.</li>
81
<li>Create the Q3SqlForm.</li>
82
<li>Set the form's record buffer to the cursor's update buffer.</li>
83
<li>Insert each widget and the field it is to edit into the form.</li>
84
<li>Use <a href="q3sqlform.html#readFields">readFields</a>() to update the editor widgets with values from the database's fields.</li>
85
<li>Display the form and let the user edit values etc.</li>
86
<li>Use <a href="q3sqlform.html#writeFields">writeFields</a>() to update the database's field values with the values in the editor widgets.</li>
88
<p>Note that a Q3SqlForm does not access the database directly, but most often via QSqlFields which are part of a <a href="q3sqlcursor.html">Q3SqlCursor</a>. A <a href="q3sqlcursor.html#insert">Q3SqlCursor::insert</a>(), <a href="q3sqlcursor.html#update">Q3SqlCursor::update</a>() or <a href="q3sqlcursor.html#del">Q3SqlCursor::del</a>() call is needed to actually write values to the database.</p>
89
<p>Some sample code to initialize a form successfully:</p>
90
<pre> QLineEdit myEditor(this);
91
Q3SqlForm myForm(this);
92
Q3SqlCursor myCursor("mytable");
94
// Execute a query to make the cursor valid
96
// Move the cursor to a valid record (the first record)
98
// Set the form's record pointer to the cursor's edit buffer (which
99
// contains the current record's values)
100
myForm.setRecord(myCursor.primeUpdate());
102
// Insert a field into the form that uses myEditor to edit the
103
// field 'somefield' in 'mytable'
104
myForm.insert(&myEditor, "somefield");
106
// Update myEditor with the value from the mapped database field
109
// Let the user edit the form
111
// Update the database
112
myForm.writeFields(); // Update the cursor's edit buffer from the form
113
myCursor.update(); // Update the database from the cursor's buffer</pre>
114
<p>If you want to use custom editors for displaying and editing data fields, you must install a custom <a href="q3sqlpropertymap.html">Q3SqlPropertyMap</a>. The form uses this object to get or set the value of a widget.</p>
115
<p>See also <a href="q3sqlform.html#installPropertyMap">installPropertyMap</a>() and <a href="q3sqlpropertymap.html">Q3SqlPropertyMap</a>.</p>
117
<h2>Member Function Documentation</h2>
118
<h3 class="fn"><a name="Q3SqlForm"></a>Q3SqlForm::Q3SqlForm ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
119
<p>Constructs a <a href="q3sqlform.html">Q3SqlForm</a> with parent <i>parent</i>.</p>
120
<h3 class="fn"><a name="dtor.Q3SqlForm"></a>Q3SqlForm::~Q3SqlForm ()</h3>
121
<p>Destroys the object and frees any allocated resources.</p>
122
<h3 class="fn"><a name="clear"></a>void Q3SqlForm::clear () <tt> [virtual slot]</tt></h3>
123
<p>Removes every widget, and the fields they're mapped to, from the form.</p>
124
<h3 class="fn"><a name="clearValues"></a>void Q3SqlForm::clearValues () <tt> [virtual slot]</tt></h3>
125
<p>Clears the values in all the widgets, and the fields they are mapped to, in the form, and sets them to NULL.</p>
126
<h3 class="fn"><a name="count"></a>int Q3SqlForm::count () const</h3>
127
<p>Returns the number of widgets in the form.</p>
128
<h3 class="fn"><a name="fieldToWidget"></a><a href="qwidget.html">QWidget</a> * Q3SqlForm::fieldToWidget ( <a href="qsqlfield.html">QSqlField</a> * <i>field</i> ) const</h3>
129
<p>Returns the widget that field <i>field</i> is mapped to.</p>
130
<h3 class="fn"><a name="insert"></a>void Q3SqlForm::insert ( <a href="qwidget.html">QWidget</a> * <i>widget</i>, const <a href="qstring.html">QString</a> & <i>field</i> ) <tt> [virtual]</tt></h3>
131
<p>Inserts a <i>widget</i>, and the name of the <i>field</i> it is to be mapped to, into the form. To actually associate inserted widgets with an edit buffer, use <a href="q3sqlform.html#setRecord">setRecord</a>().</p>
132
<p>See also <a href="q3sqlform.html#setRecord">setRecord</a>().</p>
133
<h3 class="fn"><a name="insert-2"></a>void Q3SqlForm::insert ( <a href="qwidget.html">QWidget</a> * <i>widget</i>, <a href="qsqlfield.html">QSqlField</a> * <i>field</i> ) <tt> [virtual protected]</tt></h3>
134
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
135
<p>Inserts a <i>widget</i>, and the <i>field</i> it is to be mapped to, into the form.</p>
136
<h3 class="fn"><a name="installPropertyMap"></a>void Q3SqlForm::installPropertyMap ( <a href="q3sqlpropertymap.html">Q3SqlPropertyMap</a> * <i>pmap</i> )</h3>
137
<p>Installs a custom <a href="q3sqlpropertymap.html">Q3SqlPropertyMap</a>. This is useful if you plan to create your own custom editor widgets.</p>
138
<p><a href="q3sqlform.html">Q3SqlForm</a> takes ownership of <i>pmap</i>, so <i>pmap</i> is deleted when <a href="q3sqlform.html">Q3SqlForm</a> goes out of scope.</p>
139
<p>See also <a href="q3datatable.html#installEditorFactory">Q3DataTable::installEditorFactory</a>().</p>
140
<h3 class="fn"><a name="readField"></a>void Q3SqlForm::readField ( <a href="qwidget.html">QWidget</a> * <i>widget</i> ) <tt> [virtual slot]</tt></h3>
141
<p>Updates the widget <i>widget</i> with the value from the SQL field it is mapped to. Nothing happens if no SQL field is mapped to the <i>widget</i>.</p>
142
<h3 class="fn"><a name="readFields"></a>void Q3SqlForm::readFields () <tt> [virtual slot]</tt></h3>
143
<p>Updates the widgets in the form with current values from the SQL fields they are mapped to.</p>
144
<h3 class="fn"><a name="remove"></a>void Q3SqlForm::remove ( <a href="qwidget.html">QWidget</a> * <i>widget</i> ) <tt> [virtual protected]</tt></h3>
145
<p>Removes a <i>widget</i>, and hence the field it's mapped to, from the form.</p>
146
<h3 class="fn"><a name="remove-2"></a>void Q3SqlForm::remove ( const <a href="qstring.html">QString</a> & <i>field</i> ) <tt> [virtual]</tt></h3>
147
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
148
<p>Removes <i>field</i> from the form.</p>
149
<h3 class="fn"><a name="setRecord"></a>void Q3SqlForm::setRecord ( <a href="qsqlrecord.html">QSqlRecord</a> * <i>buf</i> ) <tt> [virtual]</tt></h3>
150
<p>Sets <i>buf</i> as the record buffer for the form. To force the display of the data from <i>buf</i>, use <a href="q3sqlform.html#readFields">readFields</a>().</p>
151
<p>See also <a href="q3sqlform.html#readFields">readFields</a>() and <a href="q3sqlform.html#writeFields">writeFields</a>().</p>
152
<h3 class="fn"><a name="widget"></a><a href="qwidget.html">QWidget</a> * Q3SqlForm::widget ( int <i>i</i> ) const</h3>
153
<p>Returns the <i>i</i>-th widget in the form. Useful for traversing the widgets in the form.</p>
154
<h3 class="fn"><a name="widgetToField"></a><a href="qsqlfield.html">QSqlField</a> * Q3SqlForm::widgetToField ( <a href="qwidget.html">QWidget</a> * <i>widget</i> ) const</h3>
155
<p>Returns the SQL field that widget <i>widget</i> is mapped to.</p>
156
<h3 class="fn"><a name="writeField"></a>void Q3SqlForm::writeField ( <a href="qwidget.html">QWidget</a> * <i>widget</i> ) <tt> [virtual slot]</tt></h3>
157
<p>Updates the SQL field with the value from the <i>widget</i> it is mapped to. Nothing happens if no SQL field is mapped to the <i>widget</i>.</p>
158
<h3 class="fn"><a name="writeFields"></a>void Q3SqlForm::writeFields () <tt> [virtual slot]</tt></h3>
159
<p>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 <a href="q3sqlcursor.html#insert">Q3SqlCursor::insert</a>(), <a href="q3sqlcursor.html#update">Q3SqlCursor::update</a>() or <a href="q3sqlcursor.html#del">Q3SqlCursor::del</a>() as appropriate.</p>
160
<p /><address><hr /><div align="center">
161
<table width="100%" cellspacing="0" border="0"><tr class="address">
162
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
163
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
164
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
165
</tr></table></div></address></body>