问题描述
奇怪,我通过添加现有文件...将所需文件添加到资源中,文件就在那里.我运行 qmake ("Build->Run qmake") 以使文件可用.第一个问题:我无法从输出终端向文件中写入任何内容! 但是当我手动写入文件时,每次运行时输出终端都会显示变化它.第二个问题:它仍然显示 QIODevice::read: device not open !这是我的代码:
这是代码的输出终端:
保存在
目前,Qt 始终将数据直接存储在可执行文件中,即使在操作系统为资源提供本机支持的 Windows、macOS 和 iOS 上也是如此....
It's strange, I add desired file into the resources via Add Existing Files..., the file is there. I run qmake ("Build->Run qmake") to make the file available. The first issue: I can't write anything into the file from output terminal! But when I manually write into the file, the output terminal shows the change every time I run it. Second issue: it still says QIODevice::read: device not open ! Here's my code:
And here's output terminal of the code:
The files saved in a qresource are read-only since they are part of the executable so you can not write or modify them.
docs:
Currently, Qt always stores the data directly in the executable, even on Windows, macOS, and iOS, where the operating system provides native support for resources. ...
这篇关于如何在 Qt 5 中写入和读取 QResource 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!