您的位置:首页 > 编程语言 > Qt开发

Qt5_qt.conf

2016-07-07 17:02 537 查看
本站所有文章由本站和原作者保留一切权力,仅在保留本版权信息、原文链接、原 文作者的情况下允许转载,转载请勿删改原文内容, 并不得用于商业用途。 谢谢合作。
原文链接:用qt.conf和qtconfig配置Qt运行设定

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

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

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

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

资源系统, :/qt/etc/qt.conf

Mac系统下会在资源目录, 例如:assistant.app/Contents/Resources/qt.conf

执行档所在目录,如:QCoreApplication::applicationDirPath()+QDir::seperator()+”qt.conf”

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



默认值

PrefixQCoreApplication::applicationDirPath()
Documentationdoc
Headersinclude
Librarieslib
Binariesbin
Pluginsplugins
Data.
Translationstranslations
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:

:/qt/etc/qt.conf
using the resource system

on OS X, in the Resource directory inside the application bundle, for example
assistant.app/Contents/Resources/qt.conf


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.

EntryDefault Value
PrefixQCoreApplication::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, the
Prefix
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 by
Arguments
.

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、
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: