1 | /****************************************************************************
|
---|
2 | ** $Id: main.cpp 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | #include <qapplication.h>
|
---|
12 | #include <qdialog.h>
|
---|
13 | #include <qlabel.h>
|
---|
14 | #include <qlayout.h>
|
---|
15 | #include <qlineedit.h>
|
---|
16 | #include <qsqldatabase.h>
|
---|
17 | #include <qsqlcursor.h>
|
---|
18 | #include <qsqlform.h>
|
---|
19 | #include "../connection.h"
|
---|
20 |
|
---|
21 | class FormDialog : public QDialog
|
---|
22 | {
|
---|
23 | public:
|
---|
24 | FormDialog();
|
---|
25 | };
|
---|
26 |
|
---|
27 |
|
---|
28 | FormDialog::FormDialog()
|
---|
29 | {
|
---|
30 | QLabel *forenameLabel = new QLabel( "Forename:", this );
|
---|
31 | QLabel *forenameDisplay = new QLabel( this );
|
---|
32 | QLabel *surnameLabel = new QLabel( "Surname:", this );
|
---|
33 | QLabel *surnameDisplay = new QLabel( this );
|
---|
34 | QLabel *salaryLabel = new QLabel( "Salary:", this );
|
---|
35 | QLineEdit *salaryEdit = new QLineEdit( this );
|
---|
36 |
|
---|
37 | QGridLayout *grid = new QGridLayout( this );
|
---|
38 | grid->addWidget( forenameLabel, 0, 0 );
|
---|
39 | grid->addWidget( forenameDisplay, 0, 1 );
|
---|
40 | grid->addWidget( surnameLabel, 1, 0 );
|
---|
41 | grid->addWidget( surnameDisplay, 1, 1 );
|
---|
42 | grid->addWidget( salaryLabel, 2, 0 );
|
---|
43 | grid->addWidget( salaryEdit, 2, 1 );
|
---|
44 | grid->activate();
|
---|
45 |
|
---|
46 | QSqlCursor staffCursor( "staff" );
|
---|
47 | staffCursor.select();
|
---|
48 | staffCursor.next();
|
---|
49 |
|
---|
50 | QSqlForm sqlForm( this );
|
---|
51 | sqlForm.setRecord( staffCursor.primeUpdate() );
|
---|
52 | sqlForm.insert( forenameDisplay, "forename" );
|
---|
53 | sqlForm.insert( surnameDisplay, "surname" );
|
---|
54 | sqlForm.insert( salaryEdit, "salary" );
|
---|
55 | sqlForm.readFields();
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | int main( int argc, char *argv[] )
|
---|
60 | {
|
---|
61 | QApplication app( argc, argv );
|
---|
62 |
|
---|
63 | if ( ! createConnections() ) return 1;
|
---|
64 |
|
---|
65 | FormDialog *formDialog = new FormDialog();
|
---|
66 | formDialog->show();
|
---|
67 | app.setMainWidget( formDialog );
|
---|
68 |
|
---|
69 | return app.exec();
|
---|
70 | }
|
---|