source: trunk/examples/sql/overview/form2/main.cpp

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

Added SQL examples

File size: 2.3 KB
Line 
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 "main.h"
12
13FormDialog::FormDialog()
14 : staffCursor( "staff" )
15{
16 staffCursor.setTrimmed( "forename", TRUE );
17 staffCursor.setTrimmed( "surname", TRUE );
18
19 QLabel *forenameLabel = new QLabel( "Forename:", this );
20 QLineEdit *forenameEdit = new QLineEdit( this );
21 QLabel *surnameLabel = new QLabel( "Surname:", this );
22 QLineEdit *surnameEdit = new QLineEdit( this );
23 QLabel *salaryLabel = new QLabel( "Salary:", this );
24 QLineEdit *salaryEdit = new QLineEdit( this );
25 QPushButton *saveButton = new QPushButton( "&Save", this );
26 connect( saveButton, SIGNAL(clicked()), this, SLOT(save()) );
27
28 QGridLayout *grid = new QGridLayout( this );
29 grid->addWidget( forenameLabel, 0, 0 );
30 grid->addWidget( forenameEdit, 0, 1 );
31 grid->addWidget( surnameLabel, 1, 0 );
32 grid->addWidget( surnameEdit, 1, 1 );
33 grid->addWidget( salaryLabel, 2, 0 );
34 grid->addWidget( salaryEdit, 2, 1 );
35 grid->addWidget( saveButton, 3, 0 );
36 grid->activate();
37
38 idIndex = staffCursor.index( "id" );
39 staffCursor.select( idIndex );
40 staffCursor.first();
41
42 sqlForm = new QSqlForm( this );
43 sqlForm->setRecord( staffCursor.primeUpdate() );
44 sqlForm->insert( forenameEdit, "forename" );
45 sqlForm->insert( surnameEdit, "surname" );
46 sqlForm->insert( salaryEdit, "salary" );
47 sqlForm->readFields();
48}
49
50
51FormDialog::~FormDialog()
52{
53
54}
55
56
57void FormDialog::save()
58{
59 sqlForm->writeFields();
60 staffCursor.update();
61 staffCursor.select( idIndex );
62 staffCursor.first();
63}
64
65
66int main( int argc, char *argv[] )
67{
68 QApplication app( argc, argv );
69
70 if ( ! createConnections() )
71 return 1;
72
73 FormDialog *formDialog = new FormDialog();
74 formDialog->show();
75 app.setMainWidget( formDialog );
76
77 return app.exec();
78}
Note: See TracBrowser for help on using the repository browser.