【发布时间】:2012-11-14 03:23:57
【问题描述】:
我在 Windows7 上用 c++ qnd Qt Creator(QML) 编写了一个 Qt Quick Desktop 应用程序。现在 我必须部署它,我需要隐藏 qml 文件和图像(意味着:将它们放入资源等中)
我读到有一个很好的方法可以使用 .qrc 文件来做到这一点。我阅读了有关这些文件的文档,并为我的应用程序创建了一个,如下所示:
<RCC>
<qresource prefix="/">
<file>qml/GenericHostApplicationQML/myMain.qml</file>
<file>qml/GenericHostApplicationQML/content/PressAndHoldButton.qml</file>
<file>qml/GenericHostApplicationQML/content/TextButton.qml</file>
<file>qml/GenericHostApplicationQML/content/pics/advancedsettings.png</file>
<file>qml/GenericHostApplicationQML/content/pics/cnruninstall.png</file>
<file>qml/GenericHostApplicationQML/content/pics/dialog_cancel.png</file>
<file>qml/GenericHostApplicationQML/content/pics/folder_explore.png</file>
<file>qml/GenericHostApplicationQML/content/pics/gnome_session_switch.png</file>
<file>qml/GenericHostApplicationQML/content/pics/mail2_send.png</file>
<file>qml/GenericHostApplicationQML/content/pics/Picture1.png</file>
<file>qml/GenericHostApplicationQML/content/pics/Picture2.png</file>
</qresource>
在 main.cpp 中,我正在加载 Main.qml 文件,如下所示:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("qml/GenericHostApplicationQML/myMain.qml"));
view.show();
return app.exec();
}
我尝试从 Resources.qrc 中读取 myMain.qml 文件,例如:
view.setSource(QUrl(":/qml/GenericHostApplicationQML/myMain.qml"));//I added the ":/"
但我遇到了这个错误:
file:///qml/GenericHostApplicationQML/myMain.qml: File not found
当我尝试这个时:
view.setSource(QUrl::fromLocalFile(":/qml/GenericHostApplicationQML/myMain.qml"));
我明白了:
file:///C:/Users/ayalafre/Desktop/ghaQML/GenericHostApplicationQML-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release/:/qml/GenericHostApplicationQML/myMain.qml: File not found
我的 Qt 似乎不知道如何处理:":/"。
我必须使用 .qrc 文件:
- 加载 myMain.qml 文件
- 使用导入到 myMain.qml 中的 qml 文件
- 在我的 qml 文件中使用图像
你能解释一下有什么问题吗? 为了在 c++ 和 qml 中使用 .qrc 我必须做什么?
非常感谢:)
【问题讨论】:
-
我很确定没有办法真正隐藏 QML 代码,即使您使用资源文件,任何检查您的可执行文件的人仍然可以看到该代码,即它没有被编译、加密或以任何方式变成二进制代码。