如何在qt中读取/写入文本文件?

发布于 2024-12-15 04:12:50 字数 134 浏览 1 评论 0 原文

我的表单中有一个 QPlainTextEdit,我想阅读放置在项目的其他文件中的整个 Resource.txt 文档,并且在计时器计时后,我希望应用程序将 QPlainTextEdit 的内容保存在文档中。 我知道这是一个愚蠢的问题,但我找不到解决方案。

I have a QPlainTextEdit in my Form and I want to read the whole Resource.txt document which is placed in Other Files of my project and after a timer ticks i want the application save the contents of the QPlainTextEdit in the document.
I know it's a dumb question but I can't find a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不交电费瞎发啥光 2024-12-22 04:12:50

QTextStream.readAll() 可让您将文件读取到 QString< /代码>。 此构造函数(或方法setPlainText) for QPlainTextEdit 允许您设置在编辑器中显示的字符串。使用 QTimer 触发读取 QPlainTextEdit 内容的槽 到带有 QString在所需的时间后,使用 rel="nofollow">toPlainText 方法。再次使用 QTextStream 将结果写入文件。

QTextStream.readAll() lets you read a file to a QString. This constructor (or the method setPlainText) for QPlainTextEdit lets you set a string displayed in the editor. Use a QTimer to trigger a slot which reads the contents of the QPlainTextEdit into a QString with the toPlainText method after a desired amount of time. Write the result to file using a QTextStream again.

蓝天白云 2024-12-22 04:12:50

教程Qt 编程入门将带您构建一个文本编辑器,一旦您按照此操作,尝试添加 QTimer 来触发保存。

The tutorial Getting Started Programming with Qt takes you through building a text editor, once you have followed this, try adding a QTimer to trigger a save.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文