我有一个现有的 Qt Creator 项目,它不是 Subdirs 项目.我现在已经到了要向其中添加单元测试项目的地步.当我创建新的单元测试项目时,作为子项目添加到..."组合被禁用.
I have an existing Qt Creator project which is not a Subdirs project. I have now reached a point where I want to add a unit test project to it. When I create the new unit test project, the "Add as a subproject to..." combo is disabled.
我该怎么做?我正在考虑创建一个全新的 Subdirs 项目并将我现有的项目添加到其中,然后再添加单元测试项目.
How can I do it? I'm thinking about creating a brand new Subdirs project and adding my existing project to it, and then adding the unit test project as well.
这是应该怎么做还是有更好的方法?
Is that how it should be done or is there a better way?
推荐答案将项目类型更改为子目录项目(即使对于 gui 应用程序)也不是问题.这是向其中添加单元测试子项目的唯一方法.步骤:
It's not a problem to change the project type to a subdir project (even for a gui app). That's the only way to add a unit test sub project to it. Steps:
如前所述,将您的项目设为子目录项目:
As mentioned, make your project a subdir project:
模板 = 子目录
SUBDIRS = gui 逻辑
SUBDIRS = gui logic
选择文件 > 新建文件或项目... > 其他项目 > Qt 单元测试
Select File > New file or project ... > Other Project > Qt Unit Test
您的 .pro 文件将更新如下:
Your .pro file will be updated as follows:
SUBDIRS = gui 逻辑测试
SUBDIRS = gui logic tests
注意:如果您手动重构项目层次结构,请确保子目录的名称与该子目录中的 .pro 文件的名称匹配.
Note: If you're manually restructuring the project hierarchy, make sure the name of the sub directory matches the name of .pro file within that sub directory.
例如:
- 子目录名 = test --> pro 文件名 = test.pro
- 子目录名 = src --> pro 文件名 = src.pro
- sub directory name = test --> pro file name = test.pro
- sub directory name = src --> pro file name = src.pro
更多推荐
将单元测试项目添加到现有的 Qt Creator 项目
发布评论