简体   繁体   English

QMake条件不起作用

[英]QMake conditions don't work

I created a project in which I would like to have different source files added to my project for different platforms. 我创建了一个项目,其中希望将不同的源文件添加到针对不同平台的项目中。 For that I used conditions : 为此,我使用conditions

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled16
TEMPLATE = app

MY_WIN_SOURCES = \
        file1.cpp \
        file2.cpp

MY_WIN_HEADERS = \
        file1.h \
        file2.h


MY_LINUX_SOURCES = \
        file1.cpp \
        file3.cpp

MY_LINUX_HEADERS = \
        file1.h \
        file3.h

FORMS    += mainwindow.ui

win32 {
    SOURCES = $$MY_WIN_SOURCES
    HEADERS = $$MY_WIN_HEADERS
    message("Windows...")
} else {
    SOURCES = $$MY_LINUX_SOURCES
    HEADERS = $$MY_LINUX_HEADERS
    message("Not Windows...")
}

But when I save the *.pro file, on Windows the project tree looks like this: 但是,当我保存*.pro文件时,在Windows ,项目树如下所示:

在此处输入图片说明

which is wrong because on Windows I shouldn't have file3.h and file3.cpp files: 这是错误的,因为在Windows上我不应该具有file3.hfile3.cpp文件:

Also file3.h and file3.cpp are also compiled and the shouldn't be compiled. 还要编译file3.hfile3.cpp ,不应编译。 Also the only message that appears after saving the *.pro file is Windows... 保存*.pro文件后,唯一出现的消息是Windows...

Can anyone tell me what am I doing wrong? 谁能告诉我我在做什么错?

This is actually the feature of QtCreator. 这实际上是QtCreator的功能。 It shows you all of included files, regardless the conditions, but it should compile correctly. 它会向您显示所有包含的文件,而不管条件如何,但是它应该可以正确编译。

You can read developer's list for more info: http://lists.qt-project.org/pipermail/qt-creator/2012-March/000419.html 您可以阅读开发者列表以了解更多信息: http : //lists.qt-project.org/pipermail/qt-creator/2012-March/000419.html

My understanding from earlier discussions is that this is intentional. 我从前面的讨论中了解到,这是故意的。 The theory is that you're interested in modifying the source files in your project regardless of the build configuration you have chosen at the moment. 从理论上讲,无论您当前选择了哪种构建配置,您都对修改项目中的源文件感兴趣。

/s/ Adam / s /亚当

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM