Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 37
Registered: ‎07-13-2014
My Device: Z10
My Carrier: Vodafone

Incorrect File Path when creating a new file using QFile api

Hi All,

 

I am using blackberry cascades for development and instead of device i am using Blackberry 10 simulator for running applications.

 

Problem which i happening is that i am creating a new file which i want to save in sdcard so i gave the following path in code as :-

 

QDir dir;
	dir.mkpath("/sdcard/documents/contacts");
	dir.cd("/sdcard/documents/contacts");
	QString currentPath = QDir::currentPath();
	//QFile myFile(QDir::currentPath() + "vCardContacts.dat");
	QFile myFile("/sdcard/documents/contacts/vCardContacts.dat");

 

Now the file is created but at not the specified location but instead its getting created at:-

 

Device/misc/android/documents/contact/vCardContacts.dat

 


Please tell how is this happening and where i am making mistake. Is it because of BB10 simulator being used for runing applications.

 

Please help.  The objective is to create the file in memory card.

 

Thanks & Regards

Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: Incorrect File Path when creating a new file using QFile api

[ Edited ]

Maybe try placing a QDir::currentPath() or  "/accounts/1000/" before the 

/sdcard/documents/contacts
New Developer
Posts: 37
Registered: ‎07-13-2014
My Device: Z10
My Carrier: Vodafone

Re: Incorrect File Path when creating a new file using QFile api

This won't work because blackberry does not allows you to create directory in current path.

 

Please see below post by Mark

 

http://supportforums.blackberry.com/t5/Native-Development/Generating-vcf-file-using-ContactService-a...

 

It states that access problems are there for creating  directories in current path.

 

Please suggest something else.

Developer
Posts: 158
Registered: ‎01-03-2013
My Device: n/a
My Carrier: n/a

Re: Incorrect File Path when creating a new file using QFile api

Try this:

 

QDir dir;
SdCardInfo sDCardInfo;
if(sDCardInfo.state() == bb::device::SdCardState::Mounted)
{ dir.cd("/accounts/1000/removable/sdcard/"); dir.mkdir("My_personal_directory");
}

 To use SdCardInfo you have to add the following to your .pro file:

 

LIBS += -lbbdevice

 More info here:

 

https://developer.blackberry.com/native/reference/cascades/bb__device__sdcardinfo.html

Regards.

If my answer has been useful to you, please, click the button