QT资源系统(qrc)

QT资源系统(qrc)

官方说明 The Qt Resource System

rcc 命令

命令行输入 rcc --help

Usage: rcc [options] inputs
Qt Resource Compiler version 5.12.7

Options:
  -h, --help                 Displays this help.
  -v, --version              Displays version information.
  -o, --output <file>        Write output to <file> rather than stdout.
  -t, --temp <file>          Use temporary <file> for big resources.
  --name <name>              Create an external initialization function with
                             <name>.
  --root <path>              Prefix resource access path with root path.
  --compress <level>         Compress input files by <level>.
  --no-compress              Disable all compression.
  --threshold <level>        Threshold to consider compressing files.
  --binary                   Output a binary file for use as a dynamic
                             resource.
  --pass <number>            Pass number for big resources
  --namespace                Turn off namespace macros.
  --verbose                  Enable verbose mode.
  --list                     Only list .qrc file entries, do not generate code.
  --list-mapping             Only output a mapping of resource paths to file
                             system paths defined in the .qrc file, do not
                             generate code.
  --project                  Output a resource file containing all files from
                             the current directory.
  --format-version <number>  The RCC format version to write

Arguments:
  inputs                     Input files (*.qrc).

rcc 文件的使用

rcc 命令 把自己的qrc文件 压缩为而进制文件
这样提供给第三方项目pro使用,可以看不到原始资源,可以压缩
把rcc文件添加到第三方项目的qrc中
然后注册:

	QResource::registerResource(":/res.rcc")
	// 或者,可以无后缀
	//QResource::registerResource(":/res")

注意

以上必须是":/res.rcc"而不是"qrc:/res.rcc",否则注册失败!!!

使用rcc里面的资源,按照rcc压缩之前的qrc文件引用路径:
:/a.png 而不是qrc:/a.png ,否则路径不对!!!


版权声明:本文为WMX843230304WMX原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。