如何使Qt Moc自动化? [英] How to automate Qt moc?

查看:380
本文介绍了如何使Qt Moc自动化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从Qt命令提示符处运行以下命令:qmake -project然后make,这给了我带有Moc文件的调试文件夹.
奇怪的是,这是我的PC生成moc_.cpp文件的唯一方法.

I have to run the following commands from Qt command prompt: qmake -project then make and this gives me the debug folder with the Moc file.
This is strangely the only way my PC will generate the moc_.cpp file.

那么我该如何自动执行这些命令的任务,而不必再次使用这些命令?

So how can I automate the task of these commands so I don't have to use these commands again?

推荐答案

您不应多次运行qmake -project. -project选项旨在为您提供模板项目文件供您编辑.每次要构建时,相当于在IDE中执行的操作都将创建一个新项目".拥有初始项目后,应该手动进行编辑,在拥有新文件时添加文件,等等.如果某些头文件发生了更改,生成的Makefile将注意到该文件并调用moc来自动更新moc _ *.cpp文件.所以:

You should not run qmake -project multiple times. The -project option is meant to provide you a template project file for you to edit. An equivalent of what you are doing in an IDE would be creating a "New Project" every time you want to build. After you have the initial project, you should edit it manually, add files when you have new files, etc. If some header file changes, the generated Makefile will notice it and call moc on it to update the moc_*.cpp file automatically. So:

  1. 开始处理项目时运行qmake -project.
  2. 要生成Makefile时,运行qmake.
  3. 要构建项目时运行make.
  1. Run qmake -project when you start working on a project.
  2. Run qmake when you want to generate Makefiles.
  3. Run make when you want to build the project.

这篇关于如何使Qt Moc自动化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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