Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook

Loading the Slate font in Qt

So I'm trying to write my app for the Dev Alpha in Qt (not Cascades) as I wait for Cascades to mature.

 

Previously, I was developing in Python using my own pre-compiled Qt libraries. Everything worked fine until I tried to create a thread to handle NFC. I'm working through those issues separately.

 

In the process of moving back to C++, it seems that Qt isn't loading the Slate font like it was before. I think the Qt libraries installed with the Dev Alpha are a little broken, since they require an environment variable to be set to allow them to execute properly (<env var="QT_QPA_FONTDIR" value="/usr/lib/qt4/lib/fonts"/>). 

 

With my own compiled Qt libraries, I don't need that environment variable and everything is picked up appropriately. It could also be that my Qt is newer than the Dev Alpha's.

 

But, is there a way to solve my problem? Can I get the Slate font back using the native Qt libraries?


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Loading the Slate font in Qt

> I think the Qt libraries installed with the Dev Alpha are a little broken, since they require an environment variable to be set to allow them to execute properly (<env var="QT_QPA_FONTDIR" value="/usr/lib/qt4/lib/fonts"/>). 

Why do you think it is borken? My Qt apps for Playbook do require this variable to be properly set up (I use 

"/usr/fonts/font_repository/monotype")

 

Out of curiosity to dyou have /usr/fonts/font_repository/ folder on BB10 device?

Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook

Re: Loading the Slate font in Qt

I think it's broken because (I think) the Qt libraries that I've been compiling lately don't have this requirement. You don't need to set that environment variable anymore. I'm using 4.8.2 head.

There is a /usr/fonts/font_repository/ folder on the Dev Alpha, but I can't figure out how to set QT_QPA_FONTDIR so that it points to both directories that I want.

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Loading the Slate font in Qt

Good to know thanks. I am using old QT libs.

why don't you put your both folders in qputenv separating by : or ; ? like:

qputenv("QT_QPA_FONTDIR", "folder1:folder2"); 

Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook

Re: Loading the Slate font in Qt

Yeah, that was actually the first thing I tried. It didn't parse the folders separately, treated it as one large string. A colon (:smileyhappy: is the separator for LD_LIBRARY_PATH, but it seems that QT_QPA_FONTDIR either uses something different, or nothing at all.

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Loading the Slate font in Qt

You are right, this can specify only one folder:

QString QPlatformFontDatabase::fontDir() const
{
    QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR"));
    if (fontpath.isEmpty()) {
#ifndef QT_NO_SETTINGS
        fontpath = QLibraryInfo::location(QLibraryInfo::LibrariesPath);
        fontpath += QLatin1String("/fonts");
#endif
    }

    return fontpath;
}

void QPlatformFontDatabase::populateFontDatabase()
{
    QString fontpath = fontDir();

    if(!QFile::exists(fontpath)) {
        qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
               qPrintable(fontpath));
    }

    QDir dir(fontpath);
    dir.setNameFilters(QStringList() << QLatin1String("*.qpf2"));
    dir.refresh();
    for (int i = 0; i < int(dir.count()); ++i) {
        const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i]));
        QFile file(QString::fromLocal8Bit(fileName));
        if (file.open(QFile::ReadOnly)) {
            const QByteArray fileData = file.readAll();
            QByteArray *fileDataPtr = new QByteArray(fileData);
            registerQPF2Font(fileData, fileDataPtr);
        }
    }
}

 Why I love opensource is because you always can see how it works -)

Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook

Re: Loading the Slate font in Qt

The other great thing is that we can fix it. I'll catch one of the Qt/KDAB guys and see if this is something that needs a bug submitted or if it's already fixed.

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!