Report this

What is the reason for this report?

QFontDatabase addApplicationFont works in Embedded Linux, but not in Linux Ubuntu?

Posted on October 10, 2017

Hi,

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…

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…

Any help will be appreciated.

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");

Help me.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.