Qt Creator 和条件构建 [英] Qt Creator and conditional build

查看:32
本文介绍了Qt Creator 和条件构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,如果定义了 MACRO,我们添加了一些源文件和头文件.我们这样做,在 .pro 文件中:

In our project, we added some source and header files if a MACRO is defined. We do this like that, in the .pro file:

contains(DEFINES, MY_DEF) {
message("Support MY_DEF")
INCLUDEPATH += \
    my_include_dir
SOURCES += \
    source1.cpp \
    source2.cpp
HEADERS +=  \
    my_include_dir/header1.h \
    my_include_dir/header2.h
FORMS +=  \
    myform.ui
}

这在构建过程中工作正常.如果未定义 MY_DEF,则不会编译文件.MY_DEF 定义如下:

This works fine during the build. The files are not compiled if MY_DEF is not defined. MY_DEF is defined like that:

DEFINES += MY_DEF

奇怪的是,Qt Creator 总是在项目树中显示文件,而 MY_DEF 是否已定义.如果没有定义,它们不用于构建,但它们仍然显示和可编辑,搜索可以扫描它们等等......这是Qt Creator的错误吗?

Curiously, Qt Creator always display the files in the project tree, whereas MY_DEF is defined or not. If not defined, they are not used for the build, but they still are displayed and editable, searches can scan them, etc... Is it a bug of Qt Creator?

这不是什么大问题,只是有点烦人,因为我们不清楚一个文件是否是项目的一部分.

This is not a big issue, just a little annoying, because we don't know clearly if a file is part of the project or not.

推荐答案

这似乎是 QtCreator 以及它如何读取 .pro 文件的问题 - 它似乎实际上并未完全解析文件,而是选择仅挑选出某些位.对于仅包含在一个或另一个平台上的文件,我遇到了同样的问题 - 在 QtCreator 中,它们总是出现.

This seems to be an issue with QtCreator and how it reads the .pro files - it doesn't seem to actually fully parse the files, opting instead to just pick out certain bits. I've got the same issue with files that are only included on one platform or another - in QtCreator, they always show up.

我希望原因要么是他们不想重新实现一半的 qmake 只是为了获取文件列表,要么在某些情况下尝试正确"解析它会得到错误的答案,并且他们选择了可预见的错误,而不是随机错误.

I expect that the reason is either that they don't want to re-implement half of qmake just to get the file lists, OR that there are situations where trying to parse it 'correctly' would get the wrong answer, and they've chosen to be predictably wrong instead of randomly wrong.

这篇关于Qt Creator 和条件构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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