×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Accessing data anywhere in application

From Nokia Developer Wiki
Jump to: navigation, search
vdharankar (Talk | contribs)
hamishwillee (Talk | contribs)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[Category:S60]Developer most of the time seek for a method or a way to place the data somewhere in such a way that it can be accessed globally from anywhere.
+
{{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.  
  
There are primarily two ways in which this can be achieved.
+
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 first is the most appropriate way suggested by symbian framework
+
but second also turn to be usefull.
+
  
== 1. Using Document class ==
+
<code cpp>
 +
CEikDocument *Document() const;
 +
</code>
  
The document class is the most appropriate place to keep the data which needs to be
+
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:
accessed from the whole application according to document and view architecture.
+
the document class is accessible in several ways on of the way is to use
+
  
CEikonEnv class's global object.
+
<code cpp>
 +
#include <eikappui.h>
  
== 2. Using AppUi class ==
+
// suppose your Document class is named as 'MyDocument'
  
The application UI class aka AppUi can also serve as a placeholder to hold the
+
MyDocument* doc = static_cast <MyDocument*> (CEikonEnv::Static()->EikAppUi()->Document() );
global data( rather i would say the data that needs to be accessed from anywhere).
+
The data can be placed in AppUi class and then can be accessed from anywhere
+
using the AppUi reference which can be retrieved using the global iEikEnv object
+
  
Though the above mentioned approach is not very much prefered but also a way out.
+
// now access your data
 +
doc->myData = ... ;
  
=== Global methods ===
 
  
Also one more use of AppUi that can be done is, the globally required methods can be
+
</code>
placed in AppUi class and can be accessed using AppUi reference , which again can be retrieved using iEikEnv global object(reference).
+
[[Category:[[Category:S60 3rd Edition]]]]
+

Latest revision as of 09:34, 15 June 2012

Archived.pngArchived: 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
CompatibilityArticle
Created: vdharankar (25 Jul 2009)
Last edited: hamishwillee (15 Jun 2012)

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 = ... ;
This page was last modified on 15 June 2012, at 09:34.
67 page views in the last 30 days.
×