如何让Qt Creator解析并索引-inl.h文件?
-inl.h Files I’ve run into exactly this issue when working with Google-style C++ codebases that use -inl.h files for templates and inline functions. The problem boils down to Qt Creator not recognizing -inl.h as a valid C++ header file by default, so it skips indexing them. Here’s how to fix it step by step:
1. Update Qt Creator’s MIME Type Configuration
Qt uses MIME types to determine how to handle different file extensions. We need to tell it that -inl.h files are C++ headers:
- Open Qt Creator, go to Edit > Preferences (on Windows it’s Tools > Options).
- Navigate to Text Editor > MIME Types.
- In the "Registered MIME Types" list, find
text/x-c++hdr(this is the MIME type for C++ header files). - Click the Add button under "File patterns", type
*.inl.h, and confirm. - Restart Qt Creator to apply the change.
2. Ensure -inl.h Files Are Included in Your Project
Even if the MIME type is set, Qt Creator won’t index files that aren’t part of your project. Add your -inl.h files to the HEADERS section of your .pro file:
HEADERS += \ Foo.h \ Foo-inl.h \ Bar.h \ Bar-inl.h
After editing, run qmake (right-click your project > Run qmake) and let Qt Creator re-scan the project files.
3. Force a Full Reindex If Needed
If you still don’t see auto-completion or syntax highlighting, trigger a full reindex:
- Go to Tools > C++ > Re-Parse Current Project.
- If that doesn’t work, clear Qt Creator’s cache directory (location varies by OS):
- Windows:
%APPDATA%\QtProject\qtcreator - macOS:
~/Library/Application Support/QtProject/Qtcreator - Linux:
~/.config/QtProject/qtcreator
Delete the cache folder, restart Qt Creator, and let it reindex from scratch.
- Windows:
Once you’ve done these steps, Qt Creator should treat -inl.h files the same as regular .h files—you’ll get auto-completion, syntax highlighting, and proper usage hints for all your template and inline functions.
内容的提问来源于stack exchange,提问作者s4eed

