Qt - Using asterisk (*) in .pro-File with directories

℡╲_俬逩灬. 提交于 2019-11-30 20:16:30

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 has for loop and function $$files(directory_path: String). Also append files to SOURCES or HEADERS variable respectively.

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

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

In qmake 3.0, at least, it's possible to use something like:

SOURCES = $$files(*.cpp, true)
HEADERS = $$files(*.h, true)

The true argument will cause the files function to recursively find all files matching the pattern given by the first argument.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!