QFontDatabase :: addApplicationFont在嵌入式Linux中工作,但在Linux Ubuntu中不工作 [英] QFontDatabase::addApplicationFont works in Embedded Linux, but not in Linux Ubuntu

查看:504
本文介绍了QFontDatabase :: addApplicationFont在嵌入式Linux中工作,但在Linux Ubuntu中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Qt 4.8开发的应用程序,它同时针对嵌入式Linux Arm和Linux Ubuntu进行了编译.它使用一组我需要安装的特定字体才能运行,这是我对QFontDatabase::addApplicationFont所做的事情.当我针对嵌入式Linux进行编译时,一切正常,但是当我针对Linux Ubuntu进行编译时,我得到-1并且未加载字体.

I have an app developed with Qt 4.8 compiled for both Embedded Linux Arm as well as Linux Ubuntu. It uses a specific set of fonts which I need to have installed for it to run, something I do with QFontDatabase::addApplicationFont. Everything works fine when I compile for Embedded Linux, but when I do it for Linux Ubuntu, I got -1 and the fonts are not loaded.

我试图在网上找到解决问题的方法,但没有找到任何帮助.通过将Qt 4.6更新到4.7(无使用)或安装我已经拥有的fontconfig,解决了类似的问题.另外,我在Qt Assistant中找不到有用的东西,并检查了.ttf文件的路径.

I tried to find on the web a solution for the problem but I found no help. Similar problems were solved by updating Qt 4.6 to 4.7 (nothing of use) or by installing fontconfig, which I already have. Also I couldn't find anything useful in Qt Assistant and checked the paths to the .ttf files.

任何帮助将不胜感激.

这是我正在使用的代码:

Here is the code I'm using:

QFontDatabase::removeAllApplicationFonts();

QDir fontDir(DEFAULT_FONTS_PATH);
QStringList fontFileList = fontDir.entryList(QStringList("*.ttf"), QDir::Files | QDir::NoDotDot | QDir::NoDot);

mDebugS(QString("Found %1 fonts on folder theme/fonts").arg(fontFileList.size()));

//
qint32 fontId;

foreach (const QString& filename, fontFileList)
{
    fontId = QFontDatabase::addApplicationFont(DEFAULT_FONTS_PATH "/" + filename);

    if (Q_UNLIKELY(fontId == -1))
    {
        const QString strTemp = QString("Unable to install font %1").arg(filename);

        mLog(strTemp);
        mDebugS(strTemp);
    }
    else
        applicationFontsIdList.append(fontId);
}

mDebugS(QString::number(applicationFontsIdList.size()) + " fonts are installed");

推荐答案

我对Qt(适用于嵌入式)4.8.6遇到了相同的问题.要解决字体问题,您需要让Qt在为非嵌入式环境构建时启用对fontconfig工具的支持.可以在文档中找到相关信息( Qt满足X11要求 )

I had the same problem with Qt (for embedded) 4.8.6. To solve the font problem you need to tell Qt to enable support for the fontconfig tool when building it for the non-embedded environment. Information can be found in the documentation (Qt for X11 Requirements)

您需要在系统上安装fontconfig开发人员软件包:

You need to install the developer package of fontconfig on your system:

sudo apt-get install libfontconfig1-dev

在从源代码构建Qt之前,您需要在配置步骤中指定以下选项:

Before building Qt from source you then need to specify the following option in the configure step:

-fontconfig

使用此版本的Qt构建我的应用程序时,addApplicationFont可以正常工作,并且一切看起来都很不错.

When building my application with this version of Qt addApplicationFont works properly and everything looks great.

这篇关于QFontDatabase :: addApplicationFont在嵌入式Linux中工作,但在Linux Ubuntu中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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