【问题标题】:Is it possible to modify QT qmake variable in the parent subdirs project?是否可以在父子目录项目中修改 QT qmake 变量?
【发布时间】:2014-04-11 19:15:33
【问题描述】:

我的共享库项目结构如下:

library.pro:

TEMPLATE = subdirs
CONFIG  += ordered
SUBDIRS += libs plugins test_programs
...
QT += concurrent
...
# Those files contains pure interfaces (C++ abstract classes)
# with no implementation, and some helper classes with inline implementation.
# So there is no reason to create yet another subproject for them
HEADERS += iface/IInterface1.h \   
           iface/IInterface2.h \ # IInterface2 needs QtConcurrent
           ...

IInterface2.h:

...
#include <QtConcurrent> // ERROR HERE: file not found, i.e. qmake ignores
                        // "QT += concurrent" statement in library.pro

class MyHelperExc : public QtConcurrent::Exception
{ ... }

class IInterface2: public virtual IBaseInterface
{ ... }

所以,我的问题是:qmake 只是忽略了SUBDIRS 父项目中的变量操作。 但它在子项目中工作正常。 我做错了什么?

【问题讨论】:

  • @dtech,你有没有解决过这个问题?我希望能够按照 eraxillan 的建议去做。我正在将QuaZip 合并到我的项目中,但我遇到了this one 之类的构建问题,这意味着我必须在构建过程中修改quazip.pro 文件以链接到zlibwapi.dll。因此,我必须维护一个单独的 quazip git repo,这真是太糟糕了。

标签: c++ qt qt5 qmake qtconcurrent


【解决方案1】:
TEMPLATE = subdirs

这一行表明 library.pro 只是其他项目的容器,包含在 SUBDIRS 变量中列出的子目录中。 library.pro 中的大多数其他变量都被忽略了,除了 CONFIG += ordered,它指定子目录应该按照给定的顺序处理。

包含 IInterface2.h 的子项目都需要在其 .pro 文件中包含QT += concurrent

【讨论】:

    【解决方案2】:

    我做错了什么?

    您认为 qmake 会解析的事实,但这不是 qmake 当前的工作方式。 SUBDIRS 意味着它只会在子文件夹中查找。

    【讨论】:

    • 那么,在 library.pro qmake 中只处理 SUBDIRS 变量而不关心所有其他变量?
    • @Axilles:这不公平,但在那个阶段会忽略来源和标题。
    • 但是如果 library.pro 中的 headers/sources 将被忽略,编译器在什么阶段处理它们并产生错误?我只是想了解在哪里放置QT += concurrent 语句;(
    • @Axilles:问题不在于该声明,而在于您在 library.pro 中的 HEADERS。如果您可以上传带有示例项目的 tarball,重现问题,那么最好的办法是我可以提供具体建议。
    • 好的,我做到了:yadi.sk/d/BBhA24glKARVT 这是一个简约的子目录项目,我的问题重现了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多