Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c+中使用qrc+;和QML应用程序? 我在Windows 7上编写了C++ QND Qt Creator(QML)的QT快速桌面应用程序。现在 我必须部署它,并且我需要隐藏qml文件和映像(意味着:将它们放在资源中等等)_C++_Qt_Qml_Deploying - Fatal编程技术网

如何在c+中使用qrc+;和QML应用程序? 我在Windows 7上编写了C++ QND Qt Creator(QML)的QT快速桌面应用程序。现在 我必须部署它,并且我需要隐藏qml文件和映像(意味着:将它们放在资源中等等)

如何在c+中使用qrc+;和QML应用程序? 我在Windows 7上编写了C++ QND Qt Creator(QML)的QT快速桌面应用程序。现在 我必须部署它,并且我需要隐藏qml文件和映像(意味着:将它们放在资源中等等),c++,qt,qml,deploying,C++,Qt,Qml,Deploying,我已经读到有一种很好的方法可以用.qrc文件实现这一点。我阅读了有关这些文件的文档,并为我的应用程序创建了一个,如下所示: <RCC> <qresource prefix="/"> <file>qml/GenericHostApplicationQML/myMain.qml</file> <file>qml/GenericHostApplicationQML/content/PressAndHoldButton.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>
我试图从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,我必须做什么?< /P> 非常感谢:)

您试过这个吗:

view.setSource(QUrl("qrc:/qml/GenericHostApplicationQML/myMain.qml"));
执行此操作时:

QUrl(":/qml/GenericHostApplicationQML/myMain.qml");

路径是“file:///qml/GenericHostApplicationQML/myMain.qml“

哦,Tnx,它很管用!!!您是否应该指导我如何在qml映像源和qml导入中使用它?谢谢你!!您想直接从本地源文件而不是资源文件读取qml文件?我不明白您的意思,我将向您解释我的意思:我有一个pressandbutton.qml文件,我想在myMain.qml文件中使用它,例如:pressandbutton{source:“qrc:/qml/GenericHostApplicationQML/content/pics/dialog_cancel.png”y:647 x:250已启用:!page.isMessageMode onClicked:menu.clearOutput();}如何使myMain.qml文件从.qrc文件中知道PressAndHoldButton.qml文件?类似这样的内容:
import”qml/GenericHostApplicationQML“Item{pressandboldbutton{…}}
…我很确定没有办法真正隐藏qml代码,即使您使用资源文件,检查可执行文件的任何人仍然可以看到该代码,即它没有以任何方式编译、加密或转换为二进制代码。
QUrl(":/qml/GenericHostApplicationQML/myMain.qml");