summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/qsqlform.3qt
blob: d273db32b40f1f2c8db9cebb1e028830849ac5fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
'\" t
.TH QSqlForm 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSqlForm \- Creates and manages data entry forms tied to SQL databases
.SH SYNOPSIS
\fC#include <ntqsqlform.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQSqlForm\fR ( QObject * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QSqlForm\fR ()"
.br
.ti -1c
.BI "virtual void \fBinsert\fR ( QWidget * widget, const QString & field )"
.br
.ti -1c
.BI "virtual void \fBremove\fR ( const QString & field )"
.br
.ti -1c
.BI "uint \fBcount\fR () const"
.br
.ti -1c
.BI "QWidget * \fBwidget\fR ( uint i ) const"
.br
.ti -1c
.BI "QSqlField * \fBwidgetToField\fR ( QWidget * widget ) const"
.br
.ti -1c
.BI "QWidget * \fBfieldToWidget\fR ( QSqlField * field ) const"
.br
.ti -1c
.BI "void \fBinstallPropertyMap\fR ( QSqlPropertyMap * pmap )"
.br
.ti -1c
.BI "virtual void \fBsetRecord\fR ( QSqlRecord * buf )"
.br
.in -1c
.SS "Public Slots"
.in +1c
.ti -1c
.BI "virtual void \fBreadField\fR ( QWidget * widget )"
.br
.ti -1c
.BI "virtual void \fBwriteField\fR ( QWidget * widget )"
.br
.ti -1c
.BI "virtual void \fBreadFields\fR ()"
.br
.ti -1c
.BI "virtual void \fBwriteFields\fR ()"
.br
.ti -1c
.BI "virtual void \fBclear\fR ()"
.br
.ti -1c
.BI "virtual void \fBclearValues\fR ( bool nullify = FALSE )"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual void \fBinsert\fR ( QWidget * widget, QSqlField * field )"
.br
.ti -1c
.BI "virtual void \fBremove\fR ( QWidget * widget )"
.br
.in -1c
.SH DESCRIPTION
The QSqlForm class creates and manages data entry forms tied to SQL databases.
.PP
Typical use of a QSqlForm consists of the following steps:
.TP
Create the widgets you want to appear in the form.
.TP
Create a cursor and navigate to the record to be edited.
.TP
Create the QSqlForm.
.TP
Set the form's record buffer to the cursor's update buffer.
.TP
Insert each widget and the field it is to edit into the form.
.TP
Use readFields() to update the editor widgets with values from the database's fields.
.TP
Display the form and let the user edit values etc.
.TP
Use writeFields() to update the database's field values with the values in the editor widgets.
.PP
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.
.PP
Some sample code to initialize a form successfully:
.PP
.nf
.br
    QLineEdit  myEditor( this );
.br
    QSqlForm   myForm( this );
.br
    QSqlCursor myCursor( "mytable" );
.br
.br
    // Execute a query to make the cursor valid
.br
    myCursor.select();
.br
    // Move the cursor to a valid record (the first record)
.br
    myCursor.next();
.br
    // Set the form's record pointer to the cursor's edit buffer (which
.br
    // contains the current record's values)
.br
    myForm.setRecord( myCursor.primeUpdate() );
.br
.br
    // Insert a field into the form that uses myEditor to edit the
.br
    // field 'somefield' in 'mytable'
.br
    myForm.insert( &myEditor, "somefield" );
.br
.br
    // Update myEditor with the value from the mapped database field
.br
    myForm.readFields();
.br
    ...
.br
    // Let the user edit the form
.br
    ...
.br
    // Update the database
.br
    myForm.writeFields();  // Update the cursor's edit buffer from the form
.br
    myCursor.update();  // Update the database from the cursor's buffer
.br
.fi
.PP
If you want to use custom editors for displaying and editing data fields, you must install a custom QSqlPropertyMap. The form uses this object to get or set the value of a widget.
.PP
Note that Qt Designer provides a visual means of creating data-aware forms.
.PP
See also installPropertyMap(), QSqlPropertyMap, and Database Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSqlForm::QSqlForm ( QObject * parent = 0, const char * name = 0 )"
Constructs a QSqlForm with parent \fIparent\fR and called \fIname\fR.
.SH "QSqlForm::~QSqlForm ()"
Destroys the object and frees any allocated resources.
.SH "void QSqlForm::clear ()\fC [virtual slot]\fR"
Removes every widget, and the fields they're mapped to, from the form.
.SH "void QSqlForm::clearValues ( bool nullify = FALSE )\fC [virtual slot]\fR"
Clears the values in all the widgets, and the fields they are mapped to, in the form. If \fInullify\fR is TRUE (the default is FALSE), each field is also set to NULL.
.SH "uint QSqlForm::count () const"
Returns the number of widgets in the form.
.SH "QWidget * QSqlForm::fieldToWidget ( QSqlField * field ) const"
Returns the widget that field \fIfield\fR is mapped to.
.SH "void QSqlForm::insert ( QWidget * widget, const QString & field )\fC [virtual]\fR"
Inserts a \fIwidget\fR, and the name of the \fIfield\fR it is to be mapped to, into the form. To actually associate inserted widgets with an edit buffer, use setRecord().
.PP
See also setRecord().
.PP
Examples:
.)l sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
.SH "void QSqlForm::insert ( QWidget * widget, QSqlField * field )\fC [virtual protected]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a \fIwidget\fR, and the \fIfield\fR it is to be mapped to, into the form.
.SH "void QSqlForm::installPropertyMap ( QSqlPropertyMap * pmap )"
Installs a custom QSqlPropertyMap. This is useful if you plan to create your own custom editor widgets.
.PP
QSqlForm takes ownership of \fIpmap\fR, so \fIpmap\fR is deleted when QSqlForm goes out of scope.
.PP
See also QDataTable::installEditorFactory().
.PP
Example: sql/overview/custom1/main.cpp.
.SH "void QSqlForm::readField ( QWidget * widget )\fC [virtual slot]\fR"
Updates the widget \fIwidget\fR with the value from the SQL field it is mapped to. Nothing happens if no SQL field is mapped to the \fIwidget\fR.
.SH "void QSqlForm::readFields ()\fC [virtual slot]\fR"
Updates the widgets in the form with current values from the SQL fields they are mapped to.
.PP
Examples:
.)l sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
.SH "void QSqlForm::remove ( QWidget * widget )\fC [virtual protected]\fR"
Removes a \fIwidget\fR, and hence the field it's mapped to, from the form.
.SH "void QSqlForm::remove ( const QString & field )\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Removes \fIfield\fR from the form.
.SH "void QSqlForm::setRecord ( QSqlRecord * buf )\fC [virtual]\fR"
Sets \fIbuf\fR as the record buffer for the form. To force the display of the data from \fIbuf\fR, use readFields().
.PP
See also readFields() and writeFields().
.PP
Examples:
.)l sql/overview/custom1/main.cpp, sql/overview/form1/main.cpp, and sql/overview/form2/main.cpp.
.SH "QWidget * QSqlForm::widget ( uint i ) const"
Returns the \fIi\fR-th widget in the form. Useful for traversing the widgets in the form.
.SH "QSqlField * QSqlForm::widgetToField ( QWidget * widget ) const"
Returns the SQL field that widget \fIwidget\fR is mapped to.
.SH "void QSqlForm::writeField ( QWidget * widget )\fC [virtual slot]\fR"
Updates the SQL field with the value from the \fIwidget\fR it is mapped to. Nothing happens if no SQL field is mapped to the \fIwidget\fR.
.SH "void QSqlForm::writeFields ()\fC [virtual slot]\fR"
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 QSqlCursor::insert(), QSqlCursor::update() or QSqlCursor::del() as appropriate.
.PP
Example: sql/overview/form2/main.cpp.

.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqsqlform.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qsqlform.3qt) and the Qt
version (3.3.8).