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

后端 未结 2 1008
名媛妹妹
名媛妹妹 2021-01-02 11:23

I have a .pro file which looks like:

SOURCES += myfolder/source1.cpp \\
           myfolder/source2.cpp
HEADERS  += myfolder/header1.h\\
            myfolder         


        
2条回答
  •  渐次进展
    2021-01-02 11:45

    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
    

提交回复
热议问题