Qt - 在带有目录的 .pro-File 中使用星号 (*) [英] Qt - Using asterisk (*) in .pro-File with directories

查看:58
本文介绍了Qt - 在带有目录的 .pro-File 中使用星号 (*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .pro 文件,看起来像:

I have a .pro file which looks like:

SOURCES += myfolder/source1.cpp \
           myfolder/source2.cpp
HEADERS  += myfolder/header1.h\
            myfolder/header2.h
FORMS    += myfolder/form1.ui\
            myfolder/form2.ui

一切都很好.但是,如果我尝试使用星号包含所有文件,即:

And everything works great. However, if I try to use an asterisk to include all the files, i.e.:

SOURCES  += myfolder/*.cpp
HEADERS  += myfolder/*.h
FORMS    += myfolder/*.ui

qmake 抛出文件未找到错误:

qmake throws a file-not-found-error:

WARNING: Failure to find: myfolder\*.cpp
[...]
:-1: error: No rule to make target `myfolder/*.cpp', needed by `release/source1.o'.  Stop.

在这两种情况下,Qt-Creator 都可以找到文件.

In both cases, Qt-Creator can find the files.

有没有办法使用星号?手动输入文件很烦人.

Is there a way to use the asterisk? It's annoying to type the files manually.

谢谢!

推荐答案

起初,使用星号是不好的做法 - 尽管 qmake 允许它,但 QtCreator 无法在添加新文件、重命名文件或删除文件时正确编辑此类 *.pro.因此,请尝试使用新建文件"或添加现有文件"对话框添加新文件.

At first, using asterisk is bad practice - despite that qmake allows it, QtCreator cannot edit such *.pro correctly on adding new, renaming or deleting file. So try to add new files with "New file" or "Add existing files" dialogs.

QMake 有 for 循环和函数 $$files(directory_path: String).还要分别将文件附加到 SOURCES 或 HEADERS 变量.

QMake has for loop and function $$files(directory_path: String). Also append files to SOURCES or HEADERS variable respectively.

将所有文件而不是目录添加到变量 FILES 的简短示例(不影响构建或项目树):

Brief example, which adds all files, but not directories, to variable FILES (not affect build or project tree):

files = $$files($$PWD/src)
win32:files ~= s|\\\\|/|g
for(file, files):!exists($$file/*):FILES += $$file

如果你想检查文件是否是*.cpp,尝试使用 contains($$file, ".cpp").

If you want to check if file is *.cpp, try to use contains($$file, ".cpp").

files = $$files($$PWD/src)
win32:files ~= s|\\\\|/|g
for(file, files):!exists($$file/*):contains($$file, ".cpp"):SOURCES += $$file

这篇关于Qt - 在带有目录的 .pro-File 中使用星号 (*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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