PDA

View Full Version : QFont is not rendered correctly in a different thread



PhilippM
21st March 2011, 17:06
Hi folks,

I'm using a QPainter to draw text with QFont on a QImage. This image as later used as a texture in an opengl scene.

Since drawing the complex texture with QPainter is rather slow, I decided to do all the painting in a different thread painting on a different QImage surface, and swap the images whenever the scene has finished painting (swapping and painting is of course guarded by a mutex).

This works really great with all contents of the scene that are lines, chords, ellipses etc. But it doesn't work with the text.
Instead of the letters, solid squares are displayed.

Is there something special I have to do with the QFont object so that it can be used in a thread other than the GUI thread?
Of course, the font object is allocated in the thread where it is used, and is not used from other threads.

I'm using Qt 4.7.1 on a 64bit Linux, compiling with gcc 4.5.0.

Regards,
Philipp


EDIT: According to this posting http://labs.qt.nokia.com/2007/09/27/multi-threaded-text-layout-and-printing/
it is supposed to work if QFontDatabase::supportsThreadedFontRendering () return true, which it does. So are there additional considerations i missed?

Added after 1 1:

Sorry, I was wrong in the edit.
QFontDatabase::supportsThreadedFontRendering () returns false.
This explains why the output is garbled.

According to the comment in the linked blogpost, this means that QT_X11_NO_FONTCONFIG is defined on my system.
However, env doesn't return an environment variable of that name.
So why does Qt assume that FONTCONFIG is not available?

Do I have to specify some options when compiling Qt?

Philipp

EDIT: can i ask my qmake binary whether it was compiled with -fontconfig ?

PhilippM
21st March 2011, 19:33
I tried on openSUSE Linux 11.3 64bit and Ubuntu 10.10 64bit:
Qt 4.7.1 is compiled with -fontconfig
env displays no parameter QT_X11_NO_FONTCONFIG
however, supportsThreadedFontRendering () keeps returning false.

Any ideas?

wysota
21st March 2011, 19:57
According to the comment in the linked blogpost, this means that QT_X11_NO_FONTCONFIG is defined on my system.
However, env doesn't return an environment variable of that name.
So why does Qt assume that FONTCONFIG is not available?
It's not an environment variable but a Qt compile-time variable. You need to rebuild Qt with fontconfig support.


EDIT: can i ask my qmake binary whether it was compiled with -fontconfig ?
No.

PhilippM
21st March 2011, 20:39
I just compiled myself another Qt version from the 4.7.2 sources, using the following command



./configure -opensource -release -qt-libpng -no-qt3support -no-webkit -no-javascript-jit -no-script -no-scripttools -no-declarative -qt-libpng -qt-libjpeg -nomake examples -nomake demos -platform linux-g++-32 -fontconfig


As you can see, I'm compiling a 32bit Qt on a 64bit Linux, which I unfortunately have to do since the target platform is 32bit only.

Of course, fontconfig-32bit and fontconfig-devel-32bit packages are installed. Otherwise the ./configure would have chocked up, I suppose.

fc-list -v says fontconfig version 2.8.0 is installed.

Still, supportsThreadedFontRendering () keeps returning false.

So if this is a compile-time constant, it should have been set by configure. But still no luck.

Philipp

Added after 7 minutes:

Update:

I just cross-checked with my system-qt, which is obviously native 64bit.
Here, it return thread support is good.

So it is an issue with building QT in 32bit mode on a 64bit linux, and it is not catched by the configure script.

What to do now? Install myself a native 32bit Linux?

Philipp

Added after 16 minutes:

Update 2:

Disregard, it works!!!
The problem was i compiled myself the new Qt, I compiled my application with it, but due to LD_LIBRARY_PATH, i was still runtime-linking against the old .so. I corrected that and now I can render the fonts in every thread I want.

Works marvelous.
Really great!!!

Philipp