开发者

What's the preferred way to include QML sources in your application build?

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 f开发者_运维技巧oobar.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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜