Archived:Accessing data anywhere in application
vdharankar
(Talk | contribs) |
hamishwillee
(Talk | contribs) |
||
| (5 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
| − | [ | + | {{Archived|timestamp=20120313112701|user=roy.debjit| }} |
| + | {{ArticleMetaData <!-- v1.2 --> | ||
| + | |sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) --> | ||
| + | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
| + | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20090725 | ||
| + | |author= [[User:Vdharankar]] | ||
| + | }} | ||
| + | [[Category:Symbian]][[Category:S60 3rd Edition (initial release)]][[Category:Symbian C++]] | ||
| + | In many situations, it is useful to have a method or a way to place data somewhere that could be accessed globally in the application. One of those ways is placing the global data in the Document class. | ||
| − | + | The Document class is the most appropriate place to keep the data which needs to be accessed from the whole application, according to the Document/View architecture. A global reference to the Document class instance if accessible through the AppUi's method Document(). This method has the following signature: | |
| − | The | + | |
| − | + | ||
| − | + | <code cpp> | |
| + | CEikDocument *Document() const; | ||
| + | </code> | ||
| − | + | This means that we should perform a cast on the result value to match our actual Document class, defined in the application. Now, here's how to access your Document instance: | |
| − | + | ||
| − | + | ||
| − | + | <code cpp> | |
| + | #include <eikappui.h> | ||
| − | + | // suppose your Document class is named as 'MyDocument' | |
| − | + | MyDocument* doc = static_cast <MyDocument*> (CEikonEnv::Static()->EikAppUi()->Document() ); | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | // now access your data | |
| + | doc->myData = ... ; | ||
| − | |||
| − | + | </code> | |
| − | + | ||
| − | + | ||
Latest revision as of 09:34, 15 June 2012
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Article Metadata
In many situations, it is useful to have a method or a way to place data somewhere that could be accessed globally in the application. One of those ways is placing the global data in the Document class.
The Document class is the most appropriate place to keep the data which needs to be accessed from the whole application, according to the Document/View architecture. A global reference to the Document class instance if accessible through the AppUi's method Document(). This method has the following signature:
CEikDocument *Document() const;
This means that we should perform a cast on the result value to match our actual Document class, defined in the application. Now, here's how to access your Document instance:
#include <eikappui.h>
// suppose your Document class is named as 'MyDocument'
MyDocument* doc = static_cast <MyDocument*> (CEikonEnv::Static()->EikAppUi()->Document() );
// now access your data
doc->myData = ... ;

