×
Namespaces

Variants
Actions
(Difference between revisions)

Get private path in Qt

From Nokia Developer Wiki
Jump to: navigation, search
savaj (Talk | contribs)
savaj (Talk | contribs)
(added two more method.)
Line 16: Line 16:
 
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 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.
  
'''Source code'''
+
===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 code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
 
QString privatePathQt(QDir::currentPath());
 
QString privatePathQt(QDir::currentPath());
 
QString privatePathSymbian(privatePathQt.replace("/","\\"));
 
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>
 
</code>
  
Line 27: Line 36:
 
Similarly we can convert back it to Qt format as follows.
 
Similarly we can convert back it to Qt format as follows.
  
'''Source code'''
+
===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 code will convert path from C:\Private\ed8788dc to C:/Private/ed8788dc */
 
QString privatePathSymbian("C:\Private\ed8788dc");
 
QString privatePathSymbian("C:\Private\ed8788dc");
 
QString privatePathQt(privatePathSymbian.replace("\\","/"));
 
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>
 
</code>

Revision as of 17:18, 30 June 2009


Contents

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.

Source code

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

QString privatePathQt(QDir::currentPath());

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.

Source code

Convert using QString::replace() method

/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
QString privatePathQt(QDir::currentPath());
QString privatePathSymbian(privatePathQt.replace("/","\\"));


Convert using QDir::toNativeSeparators() method

/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
QString privatePathQt(QDir::currentPath());
QString privatePathSymbian(QDir::toNativeSeparators(privatePathQt));

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

/* this code will convert path from C:\Private\ed8788dc to C:/Private/ed8788dc */
QString privatePathSymbian("C:\Private\ed8788dc");
QString privatePathQt(privatePathSymbian.replace("\\","/"));

Convert using QDir::fromNativeSeparators () method

/* this code will convert path from C:\Private\ed8788dc to C:/Private/ed8788dc */
QString privatePathSymbian("C:\Private\ed8788dc");
QString privatePathQt(QDir::fromNativeSeparators(privatePathSymbian));
107 page views in the last 30 days.
×