×
Namespaces

Variants
Actions
(Difference between revisions)

Get private path in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Remove platform specifier categories (only need specifier for Qt if there is some platform specific behaviour). The private path is platform specific, but the API you should use are not.)
hamishwillee (Talk | contribs)
(Simplify. Add datalocation approach and separate out information on how to convert directory separators into another article)
Line 2: Line 2:
 
{{ReviewerApproved}}
 
{{ReviewerApproved}}
 
{{Abstract|visible=true|This article explains how to get the Symbian application private path where you can safely store application data.}}
 
{{Abstract|visible=true|This article explains how to get the Symbian application private path where you can safely store application data.}}
 
{{HamishW|I wouldn't use the approach outlined here. Instead I'd use [http://doc.qt.nokia.com/latest/qdesktopservices.html#StandardLocation-enum QDesktopServices::DataLocation], which should return the same place. As per documentation "Returns a directory location where persistent application data can be stored"}}
 
  
 
==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'''
Line 13: Line 14:
 
/* 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(QApplication::applicationDirPath());
+
QString myPrivateDirectory (QDesktopServices::storageLocation (QDesktopServices::DataLocation));
 
</code>
 
</code>
 
+
or
==Converting path from Qt format to Symbian format==
+
 
+
In Qt, directory separator is forwardslah ("/"), while in Symbian directory separator is backslash ("\"). So, if we use Mobile Extension APIs then we need convert path from Qt format to Symbian format.
+
 
+
===Source code===
+
Convert using '''QString::replace()''' method
+
 
<code cpp>
 
<code cpp>
/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
+
/* This method will return private path as C:/Private/ed8788dc
 +
assuming application installed on c drive and has UID ed8788dc */
 
QString privatePathQt(QApplication::applicationDirPath());
 
QString privatePathQt(QApplication::applicationDirPath());
QString privatePathSymbian(privatePathQt.replace("/","\\"));
 
 
</code>
 
</code>
  
 +
==Converting path from Qt format to Symbian format==
  
Convert using '''QDir::toNativeSeparators()''' method
+
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]].
<code cpp>
+
/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
+
QString privatePathQt(QApplication::applicationDirPath() );
+
QString privatePathSymbian(QDir::toNativeSeparators(privatePathQt));
+
</code>
+
  
==Converting path from Symbian format to Qt format==
+
== References ==
 
+
* [http://doc.qt.nokia.com/latest/qdesktopservices.html#StandardLocation-enum QDesktopServices::DataLocation]
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>[[Category:How To]]
+

Revision as of 09:51, 5 April 2011

{{{width}}}

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

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());

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.

References

63 page views in the last 30 days.