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
Highlighted
Developer
Posts: 889
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
My Carrier: Verizon
Accepted Solution

Reading file from URL

I have a file that I know to exist on the device, but any attempt to read the file fails due to the app insisting that the file does not actually exist. I am not quite sure what I am doing wrong...

 

QString fileLocation = "file:///accounts/1000/shared/misc/FileA.txt";
QString fileContents;
QFile file(fileLocation);

if(file.exists())
{
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QTextStream textStream(&file);
		fileContents = textStream.readAll();
		file.close();
	}
}

 


Read my thoughts on BlackBerry Development at news.ebscer.com
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Reading file from URL

[ Edited ]

Hi,
This should work:
QString path = QDir::currentPath() + "/shared";
QString fileLocation = path + "/misc/FileA.txt"

Also, access_shared permission should be set in bar-descriptor.xml


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 889
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
My Carrier: Verizon

Re: Reading file from URL

Thanks, that put me on the right track.

 

I needed to use

 

QString fileLocation = "/accounts/1000/shared/misc/FileA.txt";

 instead of

 

QString fileLocation = "file:///accounts/1000/shared/misc/FileA.txt";

 


Read my thoughts on BlackBerry Development at news.ebscer.com
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Reading file from URL

You're welcome. Smiley Happy Account ids (/1000) will be different in Work perimeter and may change in future OS versions, so it's better to avoid hardcoding them. currentPath() will return the correct folder.

Andrey Fidrya, @zmeyc on twitter