在应用程序构建中包含 QML 源的首选方法是什么?

发布于 2024-09-27 14:08:17 字数 460 浏览 0 评论 0原文

我正在构建一个使用混合 UI 技术的应用程序(主要是 C++,包括一些 QML 组件)。

假设我有一个 QML 项,我想使用如下语法在 QDeclarativeView 中显示它:

view = new QDeclarativeView(QUrl::fromLocalFile("foobar.qml"));

我已将 foobar.qml 添加到 Qt Creator 中的项目中,它会自动将此行添加到 .pro 文件中:

OTHER_FILES += \
    foobar.qml

现在,您可能希望将该文件包含到项目中以暗示应将其复制到构建文件夹中,但事实并非如此,并且当我运行应用程序时,我收到有关构建文件夹中缺少 foobar.qml 的错误。我不想添加自定义构建步骤只是为了复制 QML 源代码,那么是否有一些“事实上的”方法可以做到这一点?

I am building an application with mixed UI technologies (mostly C++ with some QML components included).

Suppose I have a QML item which I want to show inside a QDeclarativeView using syntax like this:

view = new QDeclarativeView(QUrl::fromLocalFile("foobar.qml"));

I have added foobar.qml to my project in Qt Creator which automatically adds this line to the .pro file:

OTHER_FILES += \
    foobar.qml

Now, you would expect including the file into the project to imply that it should be copied to the build folder, but it doesn't, and I get an error about missing foobar.qml in the build folder when I run the application. I'd hate to add custom build steps just to copy QML sources around, so is there some "de facto" way of doing this?

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

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

发布评论

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

评论(2

生寂 2024-10-04 14:08:17

一种明显的解决方案是通过 Qt 的 资源系统 包含 QML 源代码。关于部署的文档页面上暗示了这一点基于 QML 的应用程序

编辑:这是 完整的解决方案。我应该学习RTFM。

One obvious solution would be to include the QML source through Qt's resource system. This is hinted at on the doc page about deploying QML based applications.

EDIT: Here is the complete solution. I should learn to RTFM.

眉目亦如画i 2024-10-04 14:08:17

你使用影子构建吗?如果是这样,应用程序将构建在与源代码并行的目录中。为了进行测试,您可以更改 Qt Creator 中的工作目录(左侧栏中的项目,然后是构建目标的执行)。
使用资源似乎万无一失,但每次更改任何资源时都需要重新构建。

Do you use shadow builds? If so the application is build in a directory parallel to the source code. For testing you can change the working directory in Qt Creator (Projects in the left bar, then Execution of your build target).
Using resources seems fool-proof, but it requires a rebuild every time any of the resources are changed.

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