在Linux上构建静态Qt5:在部署时如何处理字体? [英] Static Qt5 build on Linux: how to handle fonts when deploying?

查看:1389
本文介绍了在Linux上构建静态Qt5:在部署时如何处理字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这些配置选项(Ubuntu 12.04)创建了Qt 5.2.0 libs的静态版本:



-opensource
-confirm-license
-force-pkg-config
-release
-static
-prefix'/ home / juzzlin / qt5'
-no-icu
-opengl desktop
-no-glib
-accessibility
-nomake示例
-nomake tests
-qt-zlib
-qt-libpng
-qt- libjpeg
-qt-sql-sqlite
-qt-xcb
-qt-pcre
-v



问题是,当我编译和链接我的应用程序对这些Qt库,它尝试从Qt安装路径/ home / juzzlin / qt5 / lib / fonts加载字体。这应该如何工作?该应用程序在我用来编译它的机器,但不是在一些其他机器上。我也不想安装Qt的东西到一些系统目录与应用程序,因为应用程序不应该这样做。



这是我得到的错误: p>

QFontDatabase:找不到字体目录/ home / juzzlin / qt5 / lib / fonts - 是否正确安装?



如何强制它在某些其他目录中搜索字体?



另一件我不明白的是,为什么我没有这个问题,当cross - 使用MXE编译Windows?

解决方案

您可以将字体文件嵌入到可执行文件中Qt资源系统。



http:// qt-project.org/doc/qt-5/resources.html



然后在您的应用程序中,您可以加载嵌入字体。

  QGuiApplication应用程式(argc,argv); 
QQuickView视图;

//加载嵌入字体。
QString fontPath =:/fonts/MyFont.ttf;
int fontId = QFontDatabase :: addApplicationFont(fontPath);
if(fontId!= -1)
{
QFont font(MyFont);
app.setFont(font);
}

我怀疑您的应用程序正在您的主目录中搜索字体,因为qmake在编译时将路径硬编码到不同的资源。要查看这些路径的值,请运行:

  qmake -query 
pre>

您可以通过包含一个qt.conf文件覆盖应用程序中的这些路径,您也可以使用qt资源系统将其嵌入到可执行文件中。



http://qt-project.org /doc/qt-5.0/qtdoc/qt-conf.html


I have created static versions of Qt 5.2.0 libs with these configure options (Ubuntu 12.04):

-opensource -confirm-license -force-pkg-config -release -static -prefix '/home/juzzlin/qt5' -no-icu -opengl desktop -no-glib -accessibility -nomake examples -nomake tests -qt-zlib -qt-libpng -qt-libjpeg -qt-sql-sqlite -qt-xcb -qt-pcre -v

Now, the problem is that when I have compiled and linked my app against these Qt libs, it tries to load fonts from the Qt installation path /home/juzzlin/qt5/lib/fonts. How is this supposed to work? The app works on the machine that I used to compile it, but not on some other machine. I also don't want to install Qt stuff to some system directories with the app, as applications shouldn't do that.

This is the error I get:

QFontDatabase: Cannot find font directory /home/juzzlin/qt5/lib/fonts - is Qt installed correctly?

How can I force it to search for fonts in some other directory?

The other thing I don't understand is that why I don't have this same problem when cross-compiling for Windows with MXE? It uses practically the same configuring options when compiling Qt libs.

解决方案

You can embed the font file(s) into your executable using the Qt resource system.

http://qt-project.org/doc/qt-5/resources.html

Then in your application, you can load the embedded font.

QGuiApplication app(argc, argv);
QQuickView view;

// Load the embedded font.
QString fontPath = ":/fonts/MyFont.ttf";
int fontId = QFontDatabase::addApplicationFont(fontPath);
if (fontId != -1)
{
    QFont font("MyFont");
    app.setFont(font);
}

I suspect that your application is searching for the fonts in your home directory because qmake hard-codes the paths to different resources at compile time. To see the values of these paths, run:

qmake -query

You can override these paths in your application by including a qt.conf file, which you can also embed into the executable using the qt resource system.

http://qt-project.org/doc/qt-5.0/qtdoc/qt-conf.html

这篇关于在Linux上构建静态Qt5:在部署时如何处理字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆