The hk_kdeclasses programmer's tutorial | ||
---|---|---|
Prev |
Sometimes the user should not have the possibility to change the data structure. To hide the design mode just set hk_drivermanager(true). Below is the program of the previous chapter.
Example 5-1. Using a table - the runtime version
1 #include <kapp.h> 2 #include <kaboutdata.h> 3 #include <kcmdlineargs.h> 4 #include <klocale.h> 5 #include <hk_classes.h> 6 #include <iostream> 7 #include <hk_kdetable.h> 8 #include <hk_kdemessages.h> 9 10 static const char *description = 11 I18N_NOOP("A hk_kdeclasses example Application"); 12 13 static const char *version = "v0.1"; 14 15 16 int main(int argc, char **argv) 17 { 18 KAboutData about("hk_kdeexample", I18N_NOOP("hk_kdeexample"), version, description, KAboutData::License_GPL, "(C) 2001 Horst Knorr", 0, 0, "hk_classes@knorrnet.de"); 19 about.addAuthor( "Horst Knorr", 0, "hk_classes@knorrnet.de" ); 20 KCmdLineArgs::init(argc, argv, &about); 21 KApplication app; 22 23 set_kdestandarddialogs(); 24 hk_drivermanager* mydrivermanager = new hk_drivermanager(true); 25 hk_kdetable* table = new hk_kdetable(NULL); 26 27 app.setMainWidget(table); 28 if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);} 29 hk_connection* myconnection = mydrivermanager->new_connection("mysql"); 30 if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);} 31 myconnection->connect(); 32 33 hk_database* mydatabase=myconnection->new_database("exampledb"); 34 if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);} 35 hk_datasource* mydatasource= mydatabase->new_table("authors"); 36 if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);} 37 38 table->set_datasource(mydatasource); 39 table->show(); 40 table->set_viewmode(); 41 42 int res= app.exec(); 43 delete mydrivermanager; 44 return res; 45 } 46 47 48 49 |