如何在QT中从.pro编译完成后执行shell命令?

发布于 2024-11-06 10:45:14 字数 61 浏览 0 评论 0原文

如果我想执行 chmod 命令、执行输出二进制文件或执行其他一些操作,我必须对 .pro 文件进行哪些更改。

What changes must I make to the .pro file if I want to execute chmod command, execute the output binary file, or do some other operations.

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

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

发布评论

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

评论(4

木槿暧夏七纪年 2024-11-13 10:45:14

我有类似的问题。我想要一个特殊的工具(版本管理器)在每次执行 Makefile 时运行代码。这是解决方案:(

中阅读Qmake 手册,配置 qmake 环境,部分:自定义 Makefile 输出)

创建您自己的 Makefile 目标。指定命令等。

mytarget.target = .buildfile
mytarget.commands = touch $mytarget.target

QMAKE_EXTRA_TARGETS += mytarget

这样,您就有了一个可以使用 make mytarget 调用的额外目标。如果您想将其与实际的构建目标联系在一起,您必须添加:

POST_TARGETDEPS += mytarget

希望有帮助。

最好的问候
D

I had a similar problem. I wanted a special tool (versioner) to run over the code every time the Makefile was executed. Here's the solution:

(to be read in the Qmake Manual, Configuring qmake's Environment, Section: Customizing Makefile Output)

Create you own Makefile target. Specify the command etc.

mytarget.target = .buildfile
mytarget.commands = touch $mytarget.target

QMAKE_EXTRA_TARGETS += mytarget

This way, you have an extra target you can call with make mytarget for example. If you want to tie it together to the actual buildtarget you'll have to add:

POST_TARGETDEPS += mytarget

Hope that helps.

Best regards
D

久随 2024-11-13 10:45:14

按给定顺序制作内容的另一种方法是使用空的“超级”目标:

super.depends = target_pre first target_post
QMAKE_EXTRA_TARGETS += super

其中 first - 是默认的 qmake 目标,target_pretarget_post一些自定义目标。现在make super就做这件事吧。

编辑:看起来在 Qt 的最新版本中,依赖项构建是并行运行的,因此该解决方案不起作用。

Another way to make things in given order is to use empty "super" target:

super.depends = target_pre first target_post
QMAKE_EXTRA_TARGETS += super

Where first - is default qmake target, and target_pre and target_post some custom targets. Now make super just do the thing.

EDIT: looks like in last versions of Qt build of dependencies is running in paralell so this solution wouldn't work.

神经大条 2024-11-13 10:45:14

如果您使用的是 Qt Creator,则可以在“项目”面板中添加自定义构建步骤: http://doc.qt.nokia.com/qtcreator-2.1/creator-build-settings.html#adding-custom-build-steps

If you are using Qt Creator, you can add custom build steps in the Projects panel: http://doc.qt.nokia.com/qtcreator-2.1/creator-build-settings.html#adding-custom-build-steps

冷情妓 2024-11-13 10:45:14

正确的答案取决于您想要什么以及何时想要。但是,正如之前发布的一些评论所示,QMAKE_POST_LINK 可能是您想要的,而不是 POST_TARGETDEPS

查看此相关帖子:
QMake:构建后执行脚本

其一,当您使用 POST_TARGETDEPS 在创建 exe 之前(在 Windows 中)或在重新创建 exe 之前(在 Linux 中)触发! QMake 的工作方式因平台和编译器而异。

重新编译 exe 时,我需要对其进行一些“符号处理”。 POST_TARGETDEPS 在 Windows(使用 mingw)和 Linux(使用 gcc)中都给我带来了问题。在Windows中,它过早地执行了我的脚本,而在Linux中,它在我修改了它之后覆盖了我的exe(即,在我在外部脚本中剥离它之后,将我的调试信息添加回exe)。然而,QMAKE_POST_LINK 在这两种情况下都运行得很好。相比之下,它也更短、更甜、更清晰!

The right answer depends on exactly what you want, and when. However, as seen in some previously posted comments here QMAKE_POST_LINK is probably what you want rather than POST_TARGETDEPS.

Check out this related post:
QMake: execute script after build

For one, when you use POST_TARGETDEPS that fires off BEFORE your exe is created (in Windows) or BEFORE it is recreated (in Linux)! QMake works differently depending upon the platform and the complier.

I needed to do some "symbols processing" on an exe when it was recompiled. POST_TARGETDEPS gave me problems in both Windows (using mingw) and Linux (using gcc). In Windows, it executed my script prematurely, and in Linux it overwrote my exe after I had modified it (i.e. added back my debugging info to the exe after I had stripped it in my external script). QMAKE_POST_LINK worked perfectly, however, in both cases. It's also short, sweet, and more clear by comparison!

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