How to automate Qt moc?

I need to run the following commands from the Qt command line: qmake -project then make , and this will give me a debug folder with a Moc file.
This is weirdly the only way my computer will generate the moc_.cpp file.

So, how can I automate the task of these commands, so I don’t need to use these commands again?

+4
source share
2 answers

You should not run qmake -project multiple times. The -project parameter -project intended to provide you with a template project file for editing. The equivalent of what you do in the IDE will create a “New Project” every time you want to build. After the initial project, you have to edit it manually, add files when you have new files, etc. If any header file changes, the generated Makefile will notice it and call moc to update the moc _ * file. Cpp automatically. So:

  • Run qmake -project when you start work on the project.
  • Run qmake if you want to create Make files.
  • Run make when you want to create a project.
+7
source

I think you have two options.

  • call qmake from the parent make process and do a multi-level build. ("Recursive make".)

  • directly starts the meta object compiler from the rules in your makefile

If the second one, this page on using a meta-object can help.

0
source

All Articles