source: trunk/doc/html/qsqlform.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 12.7 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/sql/qsqlform.cpp:61 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QSqlForm Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QSqlForm Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1>
33
34<p>The QSqlForm class creates and manages data entry forms
35tied to SQL databases.
36<a href="#details">More...</a>
37<p><tt>#include &lt;<a href="qsqlform-h.html">qsqlform.h</a>&gt;</tt>
38<p>Inherits <a href="qobject.html">QObject</a>.
39<p><a href="qsqlform-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn><a href="#QSqlForm"><b>QSqlForm</b></a> ( QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
43<li class=fn><a href="#~QSqlForm"><b>~QSqlForm</b></a> ()</li>
44<li class=fn>virtual void <a href="#insert"><b>insert</b></a> ( QWidget&nbsp;*&nbsp;widget, const&nbsp;QString&nbsp;&amp;&nbsp;field )</li>
45<li class=fn>virtual void <a href="#remove-2"><b>remove</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;field )</li>
46<li class=fn>uint <a href="#count"><b>count</b></a> () const</li>
47<li class=fn>QWidget * <a href="#widget"><b>widget</b></a> ( uint&nbsp;i ) const</li>
48<li class=fn>QSqlField * <a href="#widgetToField"><b>widgetToField</b></a> ( QWidget&nbsp;*&nbsp;widget ) const</li>
49<li class=fn>QWidget * <a href="#fieldToWidget"><b>fieldToWidget</b></a> ( QSqlField&nbsp;*&nbsp;field ) const</li>
50<li class=fn>void <a href="#installPropertyMap"><b>installPropertyMap</b></a> ( QSqlPropertyMap&nbsp;*&nbsp;pmap )</li>
51<li class=fn>virtual void <a href="#setRecord"><b>setRecord</b></a> ( QSqlRecord&nbsp;*&nbsp;buf )</li>
52</ul>
53<h2>Public Slots</h2>
54<ul>
55<li class=fn>virtual void <a href="#readField"><b>readField</b></a> ( QWidget&nbsp;*&nbsp;widget )</li>
56<li class=fn>virtual void <a href="#writeField"><b>writeField</b></a> ( QWidget&nbsp;*&nbsp;widget )</li>
57<li class=fn>virtual void <a href="#readFields"><b>readFields</b></a> ()</li>
58<li class=fn>virtual void <a href="#writeFields"><b>writeFields</b></a> ()</li>
59<li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li>
60<li class=fn>virtual void <a href="#clearValues"><b>clearValues</b></a> ( bool&nbsp;nullify = FALSE )</li>
61</ul>
62<h2>Protected Members</h2>
63<ul>
64<li class=fn>virtual void <a href="#insert-2"><b>insert</b></a> ( QWidget&nbsp;*&nbsp;widget, QSqlField&nbsp;*&nbsp;field )</li>
65<li class=fn>virtual void <a href="#remove"><b>remove</b></a> ( QWidget&nbsp;*&nbsp;widget )</li>
66</ul>
67<hr><a name="details"></a><h2>Detailed Description</h2>
68
69
70The QSqlForm class creates and manages data entry forms
71tied to SQL databases.
72<p>
73
74
75<p> Typical use of a QSqlForm consists of the following steps:
76<ul>
77<li> Create the widgets you want to appear in the form.
78<li> Create a cursor and navigate to the record to be edited.
79<li> Create the QSqlForm.
80<li> Set the form's record buffer to the cursor's update buffer.
81<li> Insert each widget and the field it is to edit into the form.
82<li> Use <a href="#readFields">readFields</a>() to update the editor widgets with values from
83the database's fields.
84<li> Display the form and let the user edit values etc.
85<li> Use <a href="#writeFields">writeFields</a>() to update the database's field values with
86the values in the editor widgets.
87</ul>
88<p> Note that a QSqlForm does not access the database directly, but
89most often via QSqlFields which are part of a <a href="qsqlcursor.html">QSqlCursor</a>. A
90<a href="qsqlcursor.html#insert">QSqlCursor::insert</a>(), <a href="qsqlcursor.html#update">QSqlCursor::update</a>() or <a href="qsqlcursor.html#del">QSqlCursor::del</a>()
91call is needed to actually write values to the database.
92<p> Some sample code to initialize a form successfully:
93<p> <pre>
94 <a href="qlineedit.html">QLineEdit</a> myEditor( this );
95 QSqlForm myForm( this );
96 <a href="qsqlcursor.html">QSqlCursor</a> myCursor( "mytable" );
97
98 // Execute a query to make the cursor valid
99 myCursor.<a href="qsqlcursor.html#select">select</a>();
100 // Move the cursor to a valid record (the first record)
101 myCursor.<a href="qsqlquery.html#next">next</a>();
102 // Set the form's record pointer to the cursor's edit buffer (which
103 // contains the current record's values)
104 myForm.<a href="#setRecord">setRecord</a>( myCursor.<a href="qsqlcursor.html#primeUpdate">primeUpdate</a>() );
105
106 // Insert a field into the form that uses myEditor to edit the
107 // field 'somefield' in 'mytable'
108 myForm.<a href="#insert">insert</a>( &amp;myEditor, "somefield" );
109
110 // Update myEditor with the value from the mapped database field
111 myForm.<a href="#readFields">readFields</a>();
112 ...
113 // Let the user edit the form
114 ...
115 // Update the database
116 myForm.<a href="#writeFields">writeFields</a>(); // Update the cursor's edit buffer from the form
117 myCursor.<a href="qsqlcursor.html#update">update</a>(); // Update the database from the cursor's buffer
118 </pre>
119
120<p> If you want to use custom editors for displaying and editing data
121fields, you must install a custom <a href="qsqlpropertymap.html">QSqlPropertyMap</a>. The form
122uses this object to get or set the value of a widget.
123<p> Note that <a href="designer-manual.html">Qt Designer</a> provides
124a visual means of creating data-aware forms.
125<p> <p>See also <a href="#installPropertyMap">installPropertyMap</a>(), <a href="qsqlpropertymap.html">QSqlPropertyMap</a>, and <a href="database.html">Database Classes</a>.
126
127<hr><h2>Member Function Documentation</h2>
128<h3 class=fn><a name="QSqlForm"></a>QSqlForm::QSqlForm ( <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
129</h3>
130Constructs a QSqlForm with parent <em>parent</em> and called <em>name</em>.
131
132<h3 class=fn><a name="~QSqlForm"></a>QSqlForm::~QSqlForm ()
133</h3>
134Destroys the object and frees any allocated resources.
135
136<h3 class=fn>void <a name="clear"></a>QSqlForm::clear ()<tt> [virtual slot]</tt>
137</h3>
138Removes every widget, and the fields they're mapped to, from the form.
139
140<h3 class=fn>void <a name="clearValues"></a>QSqlForm::clearValues ( bool&nbsp;nullify = FALSE )<tt> [virtual slot]</tt>
141</h3>
142Clears the values in all the widgets, and the fields they are
143mapped to, in the form. If <em>nullify</em> is TRUE (the default is
144FALSE), each field is also set to NULL.
145
146<h3 class=fn>uint <a name="count"></a>QSqlForm::count () const
147</h3>
148Returns the number of widgets in the form.
149
150<h3 class=fn><a href="qwidget.html">QWidget</a>&nbsp;* <a name="fieldToWidget"></a>QSqlForm::fieldToWidget ( <a href="qsqlfield.html">QSqlField</a>&nbsp;*&nbsp;field ) const
151</h3>
152Returns the widget that field <em>field</em> is mapped to.
153
154<h3 class=fn>void <a name="insert"></a>QSqlForm::insert ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;field )<tt> [virtual]</tt>
155</h3>
156Inserts a <em>widget</em>, and the name of the <em>field</em> it is to be
157mapped to, into the form. To actually associate inserted widgets
158with an edit buffer, use <a href="#setRecord">setRecord</a>().
159<p> <p>See also <a href="#setRecord">setRecord</a>().
160
161<p>Examples: <a href="sql.html#x2225">sql/overview/form1/main.cpp</a> and <a href="sql.html#x2231">sql/overview/form2/main.cpp</a>.
162<h3 class=fn>void <a name="insert-2"></a>QSqlForm::insert ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget, <a href="qsqlfield.html">QSqlField</a>&nbsp;*&nbsp;field )<tt> [virtual protected]</tt>
163</h3>
164This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
165<p> Inserts a <em>widget</em>, and the <em>field</em> it is to be mapped to, into
166the form.
167
168<h3 class=fn>void <a name="installPropertyMap"></a>QSqlForm::installPropertyMap ( <a href="qsqlpropertymap.html">QSqlPropertyMap</a>&nbsp;*&nbsp;pmap )
169</h3>
170Installs a custom <a href="qsqlpropertymap.html">QSqlPropertyMap</a>. This is useful if you plan to
171create your own custom editor widgets.
172<p> QSqlForm takes ownership of <em>pmap</em>, so <em>pmap</em> is deleted when
173QSqlForm goes out of scope.
174<p> <p>See also <a href="qdatatable.html#installEditorFactory">QDataTable::installEditorFactory</a>().
175
176<p>Example: <a href="sql.html#x2237">sql/overview/custom1/main.cpp</a>.
177<h3 class=fn>void <a name="readField"></a>QSqlForm::readField ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget )<tt> [virtual slot]</tt>
178</h3>
179Updates the widget <em>widget</em> with the value from the SQL field it
180is mapped to. Nothing happens if no SQL field is mapped to the <em>widget</em>.
181
182<h3 class=fn>void <a name="readFields"></a>QSqlForm::readFields ()<tt> [virtual slot]</tt>
183</h3>
184Updates the widgets in the form with current values from the SQL
185fields they are mapped to.
186
187<p>Examples: <a href="sql.html#x2226">sql/overview/form1/main.cpp</a> and <a href="sql.html#x2232">sql/overview/form2/main.cpp</a>.
188<h3 class=fn>void <a name="remove"></a>QSqlForm::remove ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget )<tt> [virtual protected]</tt>
189</h3>
190Removes a <em>widget</em>, and hence the field it's mapped to, from the
191form.
192
193<h3 class=fn>void <a name="remove-2"></a>QSqlForm::remove ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;field )<tt> [virtual]</tt>
194</h3>
195This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
196<p> Removes <em>field</em> from the form.
197
198<h3 class=fn>void <a name="setRecord"></a>QSqlForm::setRecord ( <a href="qsqlrecord.html">QSqlRecord</a>&nbsp;*&nbsp;buf )<tt> [virtual]</tt>
199</h3>
200Sets <em>buf</em> as the record buffer for the form. To force the
201display of the data from <em>buf</em>, use <a href="#readFields">readFields</a>().
202<p> <p>See also <a href="#readFields">readFields</a>() and <a href="#writeFields">writeFields</a>().
203
204<p>Examples: <a href="sql.html#x2238">sql/overview/custom1/main.cpp</a>, <a href="sql.html#x2227">sql/overview/form1/main.cpp</a>, and <a href="sql.html#x2233">sql/overview/form2/main.cpp</a>.
205<h3 class=fn><a href="qwidget.html">QWidget</a>&nbsp;* <a name="widget"></a>QSqlForm::widget ( uint&nbsp;i ) const
206</h3>
207Returns the <em>i</em>-th widget in the form. Useful for traversing
208the widgets in the form.
209
210<h3 class=fn><a href="qsqlfield.html">QSqlField</a>&nbsp;* <a name="widgetToField"></a>QSqlForm::widgetToField ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget ) const
211</h3>
212Returns the SQL field that widget <em>widget</em> is mapped to.
213
214<h3 class=fn>void <a name="writeField"></a>QSqlForm::writeField ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget )<tt> [virtual slot]</tt>
215</h3>
216Updates the SQL field with the value from the <em>widget</em> it is
217mapped to. Nothing happens if no SQL field is mapped to the <em>widget</em>.
218
219<h3 class=fn>void <a name="writeFields"></a>QSqlForm::writeFields ()<tt> [virtual slot]</tt>
220</h3>
221Updates the SQL fields with values from the widgets they are
222mapped to. To actually update the database with the contents of
223the record buffer, use <a href="qsqlcursor.html#insert">QSqlCursor::insert</a>(), <a href="qsqlcursor.html#update">QSqlCursor::update</a>()
224or <a href="qsqlcursor.html#del">QSqlCursor::del</a>() as appropriate.
225
226<p>Example: <a href="sql.html#x2234">sql/overview/form2/main.cpp</a>.
227<!-- eof -->
228<hr><p>
229This file is part of the <a href="index.html">Qt toolkit</a>.
230Copyright &copy; 1995-2007
231<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
232<table width=100% cellspacing=0 border=0><tr>
233<td>Copyright &copy; 2007
234<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
235<td align=right><div align=right>Qt 3.3.8</div>
236</table></div></address></body>
237</html>
Note: See TracBrowser for help on using the repository browser.