gpt4 book ai didi

c++ - 如何使用 Symbian 的 RFile 打开文件?

转载 作者:行者123 更新时间:2023-11-28 08:23:25 24 4
gpt4 key购买 nike

我刚刚开始为 Symbian 开发。我目前正在使用诺基亚 Qt。我正在尝试启动另一个基于 mime 类型的应用程序。我目前正在关注这个 example .我想尝试打开一个 .txt 文件。

我发现很难理解如何创建 RFile 以及 TDesC16 类实际上是什么/做什么?

在示例中,基本上完成工作的代码如下:

// 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));

变量 aFileName 必须是 RFile 类型。那么我将如何创建这个对象来打开存储在 Computer\Nokia C7-00\Phone memory\test.txt 中的 .txt 文件(在资源管理器中)。

最佳答案

TDesC16 是一个 Symbian 描述符,基本上是一个字符串。这是一本很好的手册:http://descriptors.blogspot.com/

至于你的问题。在示例中,aFileName 看起来像是一个描述符。所以打开 test.txt 做这样的事情:

TThreadId threadId;
User::LeaveIfError(session.StartDocument(_L("c:\test.txt"), dataType, threadId));

如果您想使用 RFile,这里有一个代码示例:

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;

关于c++ - 如何使用 Symbian 的 RFile 打开文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4972544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com