Results 1 to 4 of 4

Thread: QFont is not rendered correctly in a different thread

  1. #1
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFont is not rendered correctly in a different thread

    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/...-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 ?
    Last edited by PhilippM; 21st March 2011 at 16:18.

  2. #2
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFont is not rendered correctly in a different thread

    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?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFont is not rendered correctly in a different thread

    Quote Originally Posted by PhilippM View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFont is not rendered correctly in a different thread

    I just compiled myself another Qt version from the 4.7.2 sources, using the following command

    Qt Code:
    1. ./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
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by PhilippM; 21st March 2011 at 19:39.

Similar Threads

  1. Replies: 6
    Last Post: 4th September 2010, 22:19
  2. Problems to display a QFont in a View/Model correctly
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 8th July 2009, 12:26
  3. SVG rendered to an 8 bits indexed QImage ?
    By lauranger in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2009, 21:44
  4. changing svg graphic attributes once rendered
    By barrygp in forum Qt Programming
    Replies: 0
    Last Post: 13th December 2008, 02:09
  5. Webkit rendered fonts
    By carl in forum Qt Programming
    Replies: 0
    Last Post: 5th September 2008, 16:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.