×
Namespaces

Variants
Actions
Revision as of 04:16, 11 October 2012 by hamishwillee (Talk | contribs)

Converting between Qt and Symbian Directory Separators

From Nokia Developer Wiki
Jump to: navigation, search
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));
62 page views in the last 30 days.