Qt资源编译器rcc的-t选项如何使用?解决C1060堆空间不足
-t (--threshold) Option I’ve dealt with this exact heap space error when using RCC alongside MSVC, so let me break down how to use the -t (or --threshold) option to resolve it.
Why the error happens
The C1060 error pops up because RCC embeds large resources directly into the generated .cpp file by default. When MSVC tries to compile that massive file full of raw data blobs, it runs out of heap space. Since you can’t use a .pro file to mark resources as external (the standard workaround), the -t option is your best bet here.
What -t/--threshold does
This option sets a size limit (measured in kilobytes). Any resource larger than this threshold will be saved as an external binary .rcc file instead of being baked into the C++ code. This cuts down the size of the .cpp file drastically, which fixes the heap overflow issue for the compiler.
Adjusting your current RCC command
Looking at your existing command:
C:\Qt\Qt5.6.3\5.6.3\msvc2015\bin\rcc.exe -threshold 70 -compress -1 -name "%(Filename)" -o ".\_qt\win\qrc_%(Filename).cpp" "%(FullPath)"
You already have -threshold 70 set, which means resources over 70KB are externalized. If you’re still hitting the error, you need to lower this value to force more large resources out of the generated .cpp. For example, try setting it to 20KB:
C:\Qt\Qt5.6.3\5.6.3\msvc2015\bin\rcc.exe -threshold 20 -compress -1 -name "%(Filename)" -o ".\_qt\win\qrc_%(Filename).cpp" "%(FullPath)"
Key notes to remember
- Runtime loading: External
.rccfiles need to be registered at runtime usingQResource::registerResource(). Make sure you call this early in your application’s startup (e.g., right before you use the resources). - Distribution: You’ll need to include the generated
.rccfiles with your application package. Place them in the same directory as your executable, or use a known path that your app can access. - Tune the threshold: If you still run into issues, keep lowering the threshold. For example, setting
-threshold 1would externalize almost all non-trivial resources, which is a safe (if extreme) fix.
内容的提问来源于stack exchange,提问作者Tom

