[Qt-interest] Using font embedded as resource

Simon Hausmann simon.hausmann at nokia.com
Thu Jan 22 01:23:28 CET 2009


On Wednesday 21 January 2009 13:18:40 ext Yves Bailly wrote:
> 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.

There was a bug in Qt < 4.5 that would result in problems similar to what you 
were seeing, related to the incorrect detection of writing systems for fonts 
on Windows that are added via the resource system. Can you try today's Qt 4.5 
snapshot and see if that fixes the problem for you?


Simon



More information about the Qt-interest-old mailing list