Qt 快速静态图像
我已经静态编译了 Qt,并使用它来编译我的应用程序。我的 exe 可以在任何地方运行,但只有当我的 exe 所在目录中有 qml/Raker/images 文件夹时,它才会显示一些内容,但我希望图像包含在我的 exe 中。在 qml 中,我通过“images/layer_0.png”访问图像(这只是 20 幅图像中的一幅)。我读过一些有关资源文件的内容,但我无法完全理解它。如果你们中有人能帮忙的话,我知道该怎么做。我还想知道 Qt Creator 是否有一些内置的方法可以做到这一点。
I have compiled Qt Statically and I have used it to compile my application. My exe runs anywhere but it only shows something if there is a qml/Raker/images folder in the same directory as my exe but I want the image to be included in my exe. In qml I access the image through "images/layer_0.png"(This is only one out of 20). I have read something about a resource file but I can't completely understand it. I'm sure how to do this If any of you could just help. I also want to know if Qt Creator has some built in way of doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可以做到的,并且它内置于 Qt 中。步骤如下:
要使用 QResources 方案访问文件,请在文件前 快速“转换”所有相关要作为资源访问的图像路径,请使用 QResources 方案在 qml 中设置查看源:
view.setSource(QUrl("qrc:/main.qml"));
有关详细信息,请查看:
Yes, this can be done and it is built into Qt. The steps are as follows:
Alternatively to quickly "convert" all relative image paths to be accessed as resources, use the QResources scheme to set your view source in qml:
view.setSource(QUrl("qrc:/main.qml"));
For more information have a look at: