When using qmltestrunner to run QML unit tests, the QML engine is
destroyed and recreated. This means that the QFontDatabase used by
the StyleEngine is also destroyed and recreated. Unfortunately, the
QFontDatabase does not ask the window manager to remove fonts when it is
destroyed. Therefore, if a StyleEngine has previously loaded a font,
and then tries to load the same font in the next test run, QFontDatabase
will call the OS-specific font loading code, which (at least on Mac OS)
will generate an error.
The solution here is to make the fontIdCache that the StyleEngine uses a
member of the StyleEngineHost, which is a singleton that is preserved
across destruction and recreation of the QML engine. The StyleEngine thus
"knows" which fonts have previously been loaded, and will not try to load
them again.
When using qmltestrunner to run QML unit tests, the QML engine is destroyed and recreated. This means that the
QFontDatabase
used by theStyleEngine
is also destroyed and recreated. Unfortunately, theQFontDatabase
does not ask the window manager to remove fonts when it is destroyed. Therefore, if aStyleEngine
has previously loaded a font, and then tries to load the same font in the next test run,QFontDatabase
will call the OS-specific font loading code, which (at least on Mac OS) will generate an error.The solution here is to make the
fontIdCache
that theStyleEngine
uses a member of theStyleEngineHost
, which is a singleton that is preserved across destruction and recreation of the QML engine. TheStyleEngine
thus "knows" which fonts have previously been loaded, and will not try to load them again.