I have just started developing for Symbian. I am currently using Nokia Qt. I am trying to launch another application based on mime type. I currently am following this example. I'd like to attempt to open a .txt file.
I am finding it hard to understand how to create a RFile and what the TDesC16 class actually is / does?
In the example the code which basically does the work is following:
// Gets the UID and MIME type for the given file name.
TUid uid;
TDataType dataType;
User::LeaveIfError(session.AppForDocument(aFileName, uid, dataType));
// Runs the default application using the MIME type, dataType.
// You can also use the UID to run the application.
TThreadId threadId;
User::LeaveIfError(session.StartDocument(aFileName, dataType, threadId));
The variable aFileName must be of type RFile. So how would开发者_开发百科 I create this object to open a .txt file stored at Computer\Nokia C7-00\Phone memory\test.txt (in Explorer).
TDesC16 is a Symbian descriptor, which is basically a string. Here is a good manual: http://descriptors.blogspot.com/
As for your problem. In the example it looks like aFileName is meant to be a descriptor. So to open test.txt do something like this:
TThreadId threadId;
User::LeaveIfError(session.StartDocument(_L("c:\test.txt"), dataType, threadId));
If you want to go with RFile, here is a code sample:
RFs fs;
User::LeaveIfError(fs.Connect()); // connect to File Server
CleanupClosePushL(fs); // adding to the cleanup stack to ensure that the resources are released properly if a leave occurres while opening a file
RFile file;
User::LeaveIfError(file.Open(fs, _L("c:\test.txt"), EFileRead));
CleanupClosePushL(file);
// do something with file
CleanupStack::PopAndDestroy(2); // closes file and fs and removes them from the cleanup stack;
精彩评论