本站所有文章由本站和原作者保留一切权力,仅在保留本版权信息、原文链接、原 文作者的情况下允许转载,转载请勿删改原文内容, 并不得用于商业用途。 谢谢合作。

前面翻译加工了一篇关于Qt4 Windows程序打包发布的文章 , 里面提到了一个重要的Qt配置文件qt.conf, 这里就讲讲关于这个文件的前世今生。

(本文部分内容出自Qt文档 Using qt.conf )

经常有人写Qt程序里头用到Qt的插件,有时忘记把插件与程序一起发布,有时是不喜欢Qt预设的插件默认路径, 导致程序找不到插件。 遇到这种情况先看看那篇打包发布的文章, 默认情况下Qt运行需要的各种路径都写死在Qt库里, 如果实在不喜欢Qt的插件路径就要用到qt.conf文件了, 这个文件里的设定能override Qt库的路径。

Qt程序启动时会用QLibraryInfo类载入qt.conf文件, 按下面的路径顺序搜索 :

  1. 资源系统, :/qt/etc/qt.conf
  2. Mac系统下会在资源目录, 例如:assistant.app/Contents/Resources/qt.conf
  3. 执行档所在目录,如:QCoreApplication::applicationDirPath()+QDir::seperator()+”qt.conf”

qt.conf的格式与ini文件一致, 可以用QSettings去访问, 这个文件里要设置一个Paths选项组,其中可以设置的项如下:

默认值

Prefix QCoreApplication::applicationDirPath()
Documentation doc
Headers include
Libraries lib
Binaries bin
Plugins plugins
Data .
Translations translations
Settings .
Examples .
Demos .

Prefix应该是一个绝对路径,其他的设定都是相对于Prefix的相对路径。 这些项不用都写进去, 只设定与默认值不同的项就可以了。例如:

[Paths]

Prefix = /some/path

Translations = i18n

在这个文件里还可以给不同版本的Qt设定不同Paths, 方法是使用Paths/x.y.z的形式, 这里的x是主版本号,y是次版本号,z是补丁级别号, 如:

Paths

Paths/4

Paths/4.1

Paths/4.2.5

其中的y和z可以忽略,并且系统会选择版本上最接近的设定,如Qt4.5这里会匹配Paths/4.2.5. 而在找不到匹配的版本号时,会使用Paths的设定, 如Qt5.0匹配Paths。

好了,学会配置这个文件就不用担心插件找不到了。

PS:加载插件plugins时一定要加上子目录。例如:支持图片显示的插件必须放到/plugins/imageformats里面,否则不能显示图片

另外,还经常有人问Qt程序的字体、风格等等能不能设置, 实际上Qt提供了一个用来配置Qt设定的工具叫qtconfig, 可能多数人还不熟悉。 这个工具就可以帮用户根据自己的喜好设定Qt程序的外观。 下面看一张程序界面的截图:

这张截图已经非常说明问题, qtconfig这个工具可以负责设定Qt应用的外观、字体等等众多属性,并且可以在界面上实时预览。 有一点从图中看不出,就是这个程序只有X11的版本, 它配置的内容会保存在Linux系统用户的家目录中, 所以不同的用户还可以设置不同的内容。 该工具的文档很简单, 大家要自己编译试运行一下才能更好的理解它的功能。

1、ZC

  1.1、搜到的官网内容:

    Using qt.conf (Qt5.7)  http://doc.qt.io/qt-5/qt-conf.html

    Using qt.conf (Qt4.8)  http://doc.qt.io/qt-4.8/qt-conf.html

2、Using qt.conf (Qt5.7)  http://doc.qt.io/qt-5/qt-conf.html

Using qt.conf

You can use the qt.conf file to override paths or to specify arguments to be passed to the platform plugins.

Format and Location

The qt.conf file is an INI text file, as described in the QSettings documentation.

QLibraryInfo will load qt.conf from one of the following locations:

  1. :/qt/etc/qt.conf using the resource system
  2. on OS X, in the Resource directory inside the application bundle, for example assistant.app/Contents/Resources/qt.conf
  3. in the directory containing the application executable, i.e. QCoreApplication::applicationDirPath() + QDir::separator() + "qt.conf"

Overriding Paths

The qt.conf file can be used to override the hard-coded paths that are compiled into the Qt library. These paths are accessible using the QLibraryInfo class. Without qt.conf, the functions in QLibraryInfo return these hard-coded paths; otherwise they return the paths as specified in qt.conf.

Without qt.conf, the Qt libraries will use the hard-coded paths to look for plugins, translations, and so on. These paths may not exist on the target system, or they may not be accessible. Because of this, you may need qt.conf to make the Qt libraries look elsewhere.

The file should have a Paths group which contains the entries that correspond to each value of theQLibraryInfo::LibraryLocation enum. See the QLibraryInfo documentation for details on the meaning of the various locations.

Entry Default Value
Prefix QCoreApplication::applicationDirPath()
Documentation doc
Headers include
Libraries lib
LibraryExecutables libexec
Binaries bin
Plugins plugins
Imports imports
Qml2Imports qml
ArchData .
Data .
Translations translations
Examples examples
Tests tests
Settings .

Absolute paths are used as specified in the qt.conf file. All paths are relative to the Prefix. On Windows and X11, thePrefix is relative to the directory containing the application executable (QCoreApplication::applicationDirPath()). On OS X, the Prefix is relative to the Contents in the application bundle. For example,application.app/Contents/plugins/ is the default location for loading Qt plugins. Note that the plugins need to be placed in specific sub-directories under the plugins directory (see How to Create Qt Plugins for details).

For example, a qt.conf file could contain the following:

[Paths]
Prefix = /some/path
Translations = i18n

Note: The backslash character is treated as a special character in INI files (see QSettings). It is therefore recommended to use forward slashes for paths on Windows as well. Otherwise, an escape character is required:

Prefix = c:\\SomePath

Configuring Arguments to the Platform Plugins

The qt.conf may contain a Platforms group, whose keys are comma-delimited lists of arguments to be passed to the platform plugin. The key name is the name of the platform plugin with the first letter upper-cased followed byArguments.

For example:

[Platforms]
WindowsArguments = fontengine=freetype

would cause the Windows platform plugin to use the FreeType font engine.

  2.1、 [Platforms] 中的 WindowsArguments 具体别的使用方式:

    ZC: 我查不到更详细的内容了...

    ZC: 我现在(20160708)能查到的 另一个配置为

[Platforms]
WindowsArguments = dpiawareness=2

      ZC: dpiawareness的相关信息位于: http://doc.qt.io/qt-5/highdpi.html

3、

4、

5、

Qt5_qt.conf的更多相关文章

  1. Nginx配置文件nginx.conf中文详解(转)

    ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...

  2. Apache主配置文件httpd.conf 详解

    Apache的主配置文件:/etc/httpd/conf/httpd.conf 默认站点主目录:/var/www/html/ Apache服务器的配置信息全部存储在主配置文件/etc/httpd/co ...

  3. redis.conf配置详细解析

    # redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb ...

  4. ERROR: Unable to globalize '/usr/local/NONE/etc/php-fpm.d/*.conf' 问题的解决

    今天继续作大死,趟php7的配置的坑. 照例,安装了昨天的各种扩展之后,解压php7的压缩文件到 /usr/local/. 然后开始配置config的扩展: ./configure --prefix= ...

  5. 两个坑-Linux下Network-Manager有线未托管-DNS resolv.conf文件开机被清空

    Linux里面有两套管理网络连接的方案: 1./etc/network/interfaces(/etc/init.d/networking) 2.Network-Manager 两套方案是冲突的,不能 ...

  6. thinkphp 3.2.3 动态修改conf配置文件

    thinkphp 3.2.3 的C()方法能修改配置文件,但是是动态修改的,没有真正的更改文件. 我查了网上网友分享的方法,都不怎么合适,我就自己摸索写了一个,配置写到text.php中,我的目录如下 ...

  7. Mac 配置 php-fpm 时出现'/private/etc/php-fpm.conf': No such file or directory (2)

    https://github.com/musicode/test/issues/5 Mac 自带 php-fpm,在终端执行 php-fpm,会报如下错误: ERROR: failed to open ...

  8. Tomcat下conf下server.xml的文件配置信息

    Tomcat下conf下server.xml的文件配置信息,基本上不用做任何修改就可以使用,修改的地方就是host区域的一些配置,此文件设置端口为80. 注意:Tomcat配置文件中(即server. ...

  9. CentOS6.3 重启后/etc/resolv.conf 被还原解决办法(转)

    今天一台服务器上不了网,设置了nameserver,重启后/etc/resolv.conf文件就被自动还原了,最后发现是被Network Manager修改了.解决方法:停止Network Manag ...

随机推荐

  1. CentOS.56安装Redis监控工具RedisLive

    RedisLive是一款开源的基于WEB的reids的监控工具,以WEB的形式展现出redis中的key的情况,实例数据等信息! RedisLive在github上的地址:https://github ...

  2. html06

    1.全局函数alert();console.log();parseInt();parseString();isNaN();eval(); 用于计算表达式字符串 用于执行字符串中的js代码 eval(& ...

  3. ng-深度学习-课程笔记-0: 概述

    课程概述 这是一个专项课程(Specialization),包含5个独立的课程,学习这门课程后做了相关的笔记记录. (1) 神经网络和深度学习 (2)  改善深层神经网络:超参数调试,正则化,优化 ( ...

  4. 测试开发-web测试要点

    参数输入考虑 参数数值包含1个.多个.很多个.null.参数值前后包含空格的2种情况   数字类型:正数.负数.0.0.0.+0.0.-0.0.指数.对数.分数.小数.复数.科学计数法的测试,全角的数 ...

  5. Linux基础命令---lsusb

    lsusb      显示本机的usb设备列表,可以显示出usb的详细信息,包括设备的读取速度和描述符.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE ...

  6. HTML5 -canvas拖拽、移动 绘制图片可操作移动,拖动

    关于canvas 的基础知识就不多说了,可以进这个网址学习 http://www.w3school.com.cn/html5/html_5_canvas.asp 对于canvas 和 SVG 其实一开 ...

  7. redis 主从同步搭建

    redis 一主二从 1.redis 安装 安装教程:https://www.cnblogs.com/zwcry/p/9505949.html 2.redis主从 1)创建主从目录 mkdir /us ...

  8. ACM题目————STL + 全排列

    今天碰到一个函数,感觉挺好用的,全排列函数 next_permutation! 求全排列的函数,基本上与自己写的DFS时间复杂度差不多,毕竟是标准库.(2018-1-4 添加) 话不多说,直接上题. ...

  9. C语言程序设计实习报告

    C语言程序设计实习报告 简介 语言实践心得体会范文在科技高度发展的今天,计算机在人们之中的作用越来越突出.而c语言作为一种计算机的语言,我们学习它,有助于我们更好的了解计算机,与计算机进行交流,因此, ...

  10. 关键字union

    union有一个作用就是判断,pc是大端存储还是小端存储的,x86是小端存储的,这个东西是有cpu决定的.arm(由存储器控制器决定)和x86一样都是小端的. 下面的是一个大端小端的一个例子,代码如下 ...