×
Namespaces

Variants
Actions
(Difference between revisions)

Converting between Qt and Symbian Directory Separators

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetadata)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
Line 29: Line 29:
 
===Source code===
 
===Source code===
 
Convert using '''QString::replace()''' method
 
Convert using '''QString::replace()''' method
<code cpp>
+
<code cpp-qt>
 
/* 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(QApplication::applicationDirPath());
 
QString privatePathQt(QApplication::applicationDirPath());
Line 37: Line 37:
  
 
Convert using '''QDir::toNativeSeparators()''' method
 
Convert using '''QDir::toNativeSeparators()''' method
<code cpp>
+
<code cpp-qt>
 
/* 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(QApplication::applicationDirPath() );
 
QString privatePathQt(QApplication::applicationDirPath() );
Line 49: Line 49:
 
===Source code===
 
===Source code===
 
Convert using '''QString::replace()''' method
 
Convert using '''QString::replace()''' method
<code cpp>
+
<code cpp-qt>
 
/* 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");
Line 56: Line 56:
  
 
Convert using '''QDir::fromNativeSeparators ()''' method
 
Convert using '''QDir::fromNativeSeparators ()''' method
<code cpp>
+
<code cpp-qt>
 
/* 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(QDir::fromNativeSeparators(privatePathSymbian));
 
QString privatePathQt(QDir::fromNativeSeparators(privatePathSymbian));
 
</code>[[Category:How To]]
 
</code>[[Category:How To]]

Revision as of 04:16, 11 October 2012

Article Metadata
Article
Created: hamishwillee (05 Apr 2011)
Last edited: hamishwillee (11 Oct 2012)

This article shows how to convert between directory separators used in Qt and those used by Symbian. Note that you only need to do this if you're directly mixing Qt and Symbian C++ code.

Contents

Overview

Qt uses a forward slash directory separator ( "/") while Symbian natively uses a backslash separator ("\"). The following sections show how to convert between the sections. The example assumes you're obtaining a private directory.

Source code

Convert using QString::replace() method

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


Convert using QDir::toNativeSeparators() method

/* this code will convert path from C:/Private/ed8788dc to C:\Private\ed8788dc */
QString privatePathQt(QApplication::applicationDirPath() );
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));
55 page views in the last 30 days.
×