×
Namespaces

Variants
Actions
(Difference between revisions)

Get private path in Qt

From Nokia Developer Wiki
Jump to: navigation, search
savaj (Talk | contribs)
(added two more method.)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Qt]][[Category:Qt for S60]][[Category:How To]]
+
{{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= 20090620
 +
|author= [[User:Savaj]]
 +
}}
 +
[[Category:Qt]]
 +
 
 +
{{Abstract|visible=true|This article explains how to get the Symbian application private path where you can safely store application data.}}
  
 
==Description==
 
==Description==
  
[[Platform Security]] introduces the data caging concept. There are some folders on Symbian OS v9 that can only be accessed with certain privileges. The private folder, \private\<sid>, is one of them. It is a folder where an application can store sensitive data. Other applications, except the one with AllFiles capability, cannot read/write to the folder. In Qt you will get full path of private folder using QDir::currentPath() method. QDir::currentPath() will returns the absolute path of the application's current directory.
+
Symbian applications store their data in a secure area, known as a "private directory", or [[Symbian OS Platform Security/02. Platform Security Concepts#Data Caging Basics|data cage]]. Other applications cannot read/write this folder unless they have the manufacturer capability {{Icode|AllFiles}} - this is hard to obtain.
 +
 
 +
The private directory is located at \private\<sid>, where the SID is a special identifier that is unique to the application (usually the same value as the application UID). In Qt you will get full path of private folder using {{Icode|QDir::currentPath()}} method or {{Icode|QDesktopServices::storageLocation (QDesktopServices::DataLocation)}}. Either method returns the absolute path of the application's current directory.
 +
 
  
 
'''Source code'''
 
'''Source code'''
<code cpp>
+
<code cpp-qt>
 
/* This method will return private path as C:/Private/ed8788dc
 
/* This method will return private path as C:/Private/ed8788dc
 
assuming application installed on c drive and has UID ed8788dc */
 
assuming application installed on c drive and has UID ed8788dc */
QString privatePathQt(QDir::currentPath());
+
QString myPrivateDirectory (QDesktopServices::storageLocation (QDesktopServices::DataLocation));
 +
</code>
 +
or
 +
<code cpp-qt>
 +
/* This method will return private path as C:/Private/ed8788dc
 +
assuming application installed on c drive and has UID ed8788dc */
 +
QString privatePathQt(QApplication::applicationDirPath());
 
</code>
 
</code>
  
 
==Converting path from Qt format to Symbian format==
 
==Converting path from Qt format to Symbian format==
  
In Qt, directory separator is forwardslah ("/"), while in Symbian directory seperator is backslash ("\"). So if we use Mobile Extension APIs then we need convert path from Qt format to Symbian format.
+
In pure Qt applications you can use the returned path directly. If you need to interact with Symbian code then you will need to read [[Converting between Qt and Symbian Directory Separators]].
  
===Source code===
+
== References ==
Convert using '''QString::replace()''' method
+
* [http://doc.qt.nokia.com/latest/qdesktopservices.html#StandardLocation-enum QDesktopServices::DataLocation][[Category:MeeGo Harmattan]] [[Category:Symbian]]
<code cpp>
+
/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
+
QString privatePathQt(QDir::currentPath());
+
QString privatePathSymbian(privatePathQt.replace("/","\\"));
+
</code>
+
 
+
 
+
Convert using '''QDir::toNativeSeparators()''' method
+
<code cpp>
+
/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
+
QString privatePathQt(QDir::currentPath());
+
QString privatePathSymbian(QDir::toNativeSeparators(privatePathQt));
+
</code>
+
 
+
==Converting path from Symbian format to Qt format==
+
 
+
Similarly we can convert back it to Qt format as follows.
+
 
+
===Source code===
+
Convert using '''QString::replace()''' method
+
<code cpp>
+
/* this code will convert path from C:\Private\ed8788dc to C:/Private/ed8788dc */
+
QString privatePathSymbian("C:\Private\ed8788dc");
+
QString privatePathQt(privatePathSymbian.replace("\\","/"));
+
</code>
+
 
+
Convert using '''QDir::fromNativeSeparators ()''' method
+
<code cpp>
+
/* this code will convert path from C:\Private\ed8788dc to C:/Private/ed8788dc */
+
QString privatePathSymbian("C:\Private\ed8788dc");
+
QString privatePathQt(QDir::fromNativeSeparators(privatePathSymbian));
+
</code>
+

Latest revision as of 04:16, 11 October 2012

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: savaj (20 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

This article explains how to get the Symbian application private path where you can safely store application data.

[edit] Description

Symbian applications store their data in a secure area, known as a "private directory", or data cage. Other applications cannot read/write this folder unless they have the manufacturer capability AllFiles - this is hard to obtain.

The private directory is located at \private\<sid>, where the SID is a special identifier that is unique to the application (usually the same value as the application UID). In Qt you will get full path of private folder using QDir::currentPath() method or QDesktopServices::storageLocation (QDesktopServices::DataLocation). Either method returns the absolute path of the application's current directory.


Source code

/* This method will return private path as C:/Private/ed8788dc
assuming application installed on c drive and has UID ed8788dc */

QString myPrivateDirectory (QDesktopServices::storageLocation (QDesktopServices::DataLocation));

or

/* This method will return private path as C:/Private/ed8788dc
assuming application installed on c drive and has UID ed8788dc */

QString privatePathQt(QApplication::applicationDirPath());

[edit] Converting path from Qt format to Symbian format

In pure Qt applications you can use the returned path directly. If you need to interact with Symbian code then you will need to read Converting between Qt and Symbian Directory Separators.

[edit] References

This page was last modified on 11 October 2012, at 04:16.
121 page views in the last 30 days.
×