[Qt-interest] Using font embedded as resource

Yves Bailly yves.bailly at sescoi.fr
Wed Jan 21 13:18:40 CET 2009


Hello all,

For some reason, I have to embed a font file (TrueType) as a resource
in my executable, using a line like this one in the resource file:
<RCC>
     <qresource prefix="/fonts" >
         <file alias="MyFont" >fonts/MyFont.ttf</file>
     </qresource>
     <!-- other resources, images, etc. -->
</RCC>

On application startup, the font is loaded like this:
QApplication app(argc, argv);
int res = QFontDatabase::addApplicationFont(":/fonts/MyFont");

The returned value ('res') is 0, meaning the font has been successfully
loaded. I can even get its family name, "MyFont". The font is used using
a simple something.setFont(QFont("MyFont")).

Now the problem.

When compiled and run on a (Linux) system where the font is
installed sytem-wide, everything works fine. When compiled and run
on a (Windows) system where the font is not installed at all, I
notice some rendering errors, for example the character U+0x2699 is
not rendered correctly.
Using Qt 4.4.3 on both system.

What can be the origin of this different behaviour? How can I be
*sure* the font actually used is the one I manually loaded?

Any hint appreciated.

-- 
     /- Yves Bailly - Software developper  -\
     \- Sescoi France http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."




More information about the Qt-interest-old mailing list