强制 QtCreator 运行“qmake"建造时 [英] Force QtCreator to run "qmake" when building

查看:38
本文介绍了强制 QtCreator 运行“qmake"建造时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一些项目中,我使用了一些在 .pro 文件中配置的预构建步骤.所以qmake只要激活就会执行这一步.

In some of my projects I use some pre-build step(s) configured in the .pro file. So qmake will execute this step whenever it is activated.

现在在 QtCreator 中,当我构建时(以及完全重建整个项目时),它并不总是运行 qmake,因为它试图变得聪明并优化它.它仅在 .pro 文件已更改时运行它,从而导致多个问题.

Now in QtCreator, when I build (also when completely rebuilding the whole project), it doesn't always run qmake, since it tries to be clever and optimize this. It only runs it when the .pro file has been changed, causing several issues.

还有一个常见的问题是,当您在该文件上运行 qmake 之后 创建一个继承自 QObject 的类时,它不会注意到它,因此 运行 moc 就可以了.这些问题可以通过简单地通过 QtCreator 中的构建"菜单手动运行 qmake 来解决.但是,如果我忘记了这一点,我有时会被因此而导致的编译错误所迷惑,这真的很烦人.

Also a common issue is, when you make a class inheriting from QObject after running qmake on that file, it will not notice it and hence not run moc on it. Such issues are solved by simply manually running qmake via the "Build" menu in QtCreator. But if I forget this I am sometimes confused by the compile errors I get because of this and this is really annoying.

(如何)我可以强制 QtCreator 在构建项目时总是做这一步?

(How) can I force QtCreator to do this step always when building a project?

我想在项目配置中添加 qmake 作为构建步骤,但这似乎是解决这个问题的肮脏技巧.

I thought about adding qmake as a build step in the project configuration, but this seems to be a dirty hack to solve this problem.

推荐答案

另一个肮脏的 hack 但更灵活一点:在 Linux/Mac 上添加touch yourprojectfile.pro"作为构建步骤或分配外部工具调用.就像在您当前的项目工作目录中运行的 touch "*.pro" 一样.当 pro 文件被更改(通过触摸模仿)时,将执行 qmake.不是更干净,但外部工具加上热键解决方案比将 qmake 添加到每个项目的构建步骤中更灵活.

Another dirty hack but a little more flexible: On Linux/Mac add "touch yourprojectfile.pro" as a build step or assign an external tool call to sth. like touch "*.pro" run in your current projects working directory. When the pro file is altered (which is mimicked by touch) qmake is executed. Not much cleaner but the external tool plus hotkey solution is more flexible than adding qmake into the buildsteps of each an every project.

更新:我终于找到了一个完全令人满意的解决方案.在 pro 文件中添加:

Update: I finally found a completely satisfactory solution for this. In the pro file add:

  qmakeforce.target = dummy
  qmakeforce.commands = rm -f Makefile ##to force rerun of qmake
  qmakeforce.depends = FORCE
  PRE_TARGETDEPS += $$qmakeforce.target
  QMAKE_EXTRA_TARGETS += qmakeforce

这会删除生成的 Makefile,从而强制 qmake 为每个构建重新运行.

This deletes the generated Makefile an thus forces qmake to rerun for every build.

这篇关于强制 QtCreator 运行“qmake"建造时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆