Now we try to open the form "demo" that we created in the knoda tutorial. It is loosely based on example 2. The most important parts are again highlighted.
Example 4-1. Using a form
1 2 3 #include <kapp.h> 4 #include <kaboutdata.h> 5 #include <kcmdlineargs.h> 6 #include <klocale.h> 7 #include <hk_classes.h> 8 #include <iostream> 9 #include <hk_kdeform.h> 10 #include <hk_kdemessages.h> 11 12 static const char *description = 13 I18N_NOOP("A hk_kdeclasses example Application"); 14 15 static const char *version = "v0.1"; 16 17 18 int main(int argc, char **argv) 19 { 20 KAboutData about("hk_kdeexample", I18N_NOOP("hk_kdeexample"), version, description, 21 KAboutData::License_GPL, "(C) 2001 Horst Knorr", 0, 0, "hk_classes@knorrnet.de"); 22 about.addAuthor( "Horst Knorr", 0, "hk_classes@knorrnet.de" ); 23 KCmdLineArgs::init(argc, argv, &about); 24 KApplication app; 25 26 hk_kdeform* form = new hk_kdeform(NULL); 27 app.setMainWidget(form); 28 29 set_kdestandarddialogs(); 30 hk_drivermanager* mydrivermanager = new hk_drivermanager(false); 31 if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);} 32 hk_connection* myconnection = mydrivermanager->new_connection("mysql"); 33 if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);} 34 myconnection->connect(); 35 36 hk_database* mydatabase=myconnection->new_database("exampledb"); 37 if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);} 38 hk_datasource* mydatasource= mydatabase->new_table("authors"); 39 if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);} 40 41 form->set_database(mydatabase); 42 form->load_form("demo"); 43 form->set_viewmode(); 44 form->show(); 45 46 int res= app.exec(); 47 delete mydrivermanager; 48 return res; 49 } 50 51 52 |
The hk_kdeform needs only the database and then loads the (supposedly) existing form "demo". Finally set the view mode to see the data.