I have a file "settings.ini" which needs to reside next to the Qt executable.
我有一个文件“设置”。它需要位于Qt可执行文件的旁边。
I can add a custom build step for this in Qt Creator which calls something like this:
我可以在Qt创建者中添加一个自定义构建步骤,调用如下:
copy %{sourceDir}/settings.ini %{buildDir}/settings.ini
This works great so far, but I'd like to include this in the *.pro file so I can put this up in our SVN too.
这到目前为止效果很好,但是我想把它包含在*中。pro文件,这样我也可以把这个放到SVN中。
How can I do this using qmake/.pro-files only?
我如何使用qmake/。pro-files只?
3 个解决方案
#1
11
You probably want to use the INSTALLS
keyword in QMake. It will require you to run make install
after your build, but it does work cross-platform.
您可能希望在QMake中使用install关键字。它将要求您在构建之后运行make install,但是它确实可以在跨平台上工作。
install_it.path = %{buildDir}
install_it.files += %{sourceDir}/settings.ini
INSTALLS += install_it
#2
8
To copy %{sourceDir}/settings.ini
to the build directory without requiring to call make install
use:
复制% { sourceDir } /设置。ini到构建目录,不需要调用make install use:
copydata.commands = $(COPY_DIR) $$PWD/settings.ini $$OUT_PWD
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
$$PWD
is the path of current .pro
file. If your settings.ini
file is not located in the same directory than the project file, then use something like $$PWD/more_dirs_here/settings.ini
$$PWD是当前.pro文件的路径。如果您的设置。ini文件与项目文件不在同一个目录中,然后使用$$PWD/more_dirs_here/settings.ini之类的东西
Note: I found this solution here. I recommend to read the whole article as it explains how it works.
注意:我在这里找到了这个解。我建议阅读整篇文章,因为它解释了它是如何工作的。
#3
1
for osx bundles you can handle it this way see Resource files in OS X bundle
对于osx包,可以这样处理,请参阅OS X包中的资源文件
add this to you project file:
将此添加到您的项目文件:
APP_QML_FILES.files = path/to/file1.qml path/to/file2.qml
APP_QML_FILES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_QML_FILES
this example copies the files to Contents/Resources
本示例将文件复制到内容/资源。
#1
11
You probably want to use the INSTALLS
keyword in QMake. It will require you to run make install
after your build, but it does work cross-platform.
您可能希望在QMake中使用install关键字。它将要求您在构建之后运行make install,但是它确实可以在跨平台上工作。
install_it.path = %{buildDir}
install_it.files += %{sourceDir}/settings.ini
INSTALLS += install_it
#2
8
To copy %{sourceDir}/settings.ini
to the build directory without requiring to call make install
use:
复制% { sourceDir } /设置。ini到构建目录,不需要调用make install use:
copydata.commands = $(COPY_DIR) $$PWD/settings.ini $$OUT_PWD
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
$$PWD
is the path of current .pro
file. If your settings.ini
file is not located in the same directory than the project file, then use something like $$PWD/more_dirs_here/settings.ini
$$PWD是当前.pro文件的路径。如果您的设置。ini文件与项目文件不在同一个目录中,然后使用$$PWD/more_dirs_here/settings.ini之类的东西
Note: I found this solution here. I recommend to read the whole article as it explains how it works.
注意:我在这里找到了这个解。我建议阅读整篇文章,因为它解释了它是如何工作的。
#3
1
for osx bundles you can handle it this way see Resource files in OS X bundle
对于osx包,可以这样处理,请参阅OS X包中的资源文件
add this to you project file:
将此添加到您的项目文件:
APP_QML_FILES.files = path/to/file1.qml path/to/file2.qml
APP_QML_FILES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_QML_FILES
this example copies the files to Contents/Resources
本示例将文件复制到内容/资源。