PDA

View Full Version : Qt Creator How to tell Creator about files that are not C++ files



doug9f
29th January 2020, 03:13
I have some files in my C++ project that are other than .cpp or .h files. One is an .ini file; others have to do with my code generation.

How do I tell Creator about these files so they show up on the navigator panel so that I can edit them?

To have .cpp files show up, I code these in the .pro file: SOURCE+=...; for .h files, HEADERS+=...

I have coded DISTFILES+=... in the .pro file which causes things to show up in the Navigator, but I'm certain that's an incorrect usage of DISTFILES.

Lesiok
29th January 2020, 08:10
It is correct. After using "Add existing file" to project and select an INI file Qt Creator creates DISTFILES rule in pro file.

doug9f
29th January 2020, 17:27
It is correct. After using "Add existing file" to project and select an INI file Qt Creator creates DISTFILES rule in pro file.

I just found this here (https://stackoverflow.com/questions/38102160/in-qt-when-should-you-use-resources-vs-distfiles-vs-other-files) (I edited the typos):


DISTFILES: Something special for Unix you won't use in most cases. From the docs:
Specifies a list of files to be included in the dist target. This feature is supported by UnixMake specs only.

OTHER_FILES: Files, that are part of you project, but not of the "build". This can be things like a readme, build hints, or any other stuff, that does not fit into any other categories

RESOURCES: .qrc-files, that will be compiled into the application.

Regarding the usage of those three with QML: You can basically use DISTFILES or OTHER_FILES for other files. In QtCreator they appear in a node as other files. These two are exchangeable for most developers. The Qt examples are local project, thus either they don't require a resource or have both, i.e. you can find the QML-files in for example OTHER_FILES and RESOURCES.

For QML-files, you should always use RESOURCES, to make sure they are within your binary.


The description of DISTFILES above is straight out of the Qt manual https://doc.qt.io/qt-5/qmake-variable-reference.html#distfiles. That description says nothing about Qt Explorer. And there is no mention of OTHER_FILES in the Qt documentation, nor how to have files show up in Qt Explorer. I would consider this a bug in the documentation, wouldn't you?

Added after 17 minutes:

When you add a plain text file using OTHER_FILES or DISTFILES, the editor still thinks its a C++ file, so it gives warning messages in the editor. To eliminate the warning messages, do the following:

Select Tools/Options/Environment/MIME Types.
Find "text/plain" on the list.
Edit the pattern of file names to include yours, e.g., *.txt;*.asc;*.dbt
Press APPLY or OK to save the changes.

The editor will no longer think you xxx.dbt files are C++ and the warnings will go away.