Force QtCreator to run “qmake” when building

て烟熏妆下的殇ゞ 提交于 2019-12-03 12:57:31

问题


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.

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.

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.

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

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.


回答1:


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.

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

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




回答2:


I think your best option is customize your QtCreator .This can be done by write a plugin for QtCreator ,or you can change the souce code of a plugin named Qt4ProjectManager ,then build it for yourself . This might be complex ,however, can be a solution.




回答3:


What I've done is created a makefile that explicitly calls qmake. Of course, that means I have two makefiles, but in my project file, I have

MAKEFILE = makefile_qt

which means that the generated makefile will have that name.

So, for the makefile I manually created, I have:

default: 
    qmake;
    ${MAKE} -f makefile_qt;

Then, from QtCreator, I just call the regular make, which will default to makefile. Or you can leave the Qt-generated makefile as is, and just call make -f makefile to call your manually created one. I forget which has precedence, makefile or Makefile, and I'm not sure if it is always the same.




回答4:


I'm using the following codes in my .pro file.

QMAKE_CLEAN += ./Makefile

This makes run qmake whenever executing clean.



来源:https://stackoverflow.com/questions/12873437/force-qtcreator-to-run-qmake-when-building

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!