Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFontDatabase falls over in c++ library

QFontDatabase falls over in c++ library

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theunsheydenrych
    wrote on last edited by
    #1

    hi
    I developed a c++ library with Qt Creator for linux that generate png images from svg files, these images is then passsed back to the caller in a byte buffer.
    I also written a c++ application with Qt Creator that uses this library for testing purposes, to verify that the library is working correctly.
    I then created proxy library for java via swig, to utilise the library from a java application to create images/png's via the c++ library.

    Everything work correctly in the Qt Creator application that uses the library.
    When uses the library from java, the application falls over, when a svg file with a text element have to be rendered.

    The error output that i get from java, hints that the code is falling over in the c++ library when parsing fontnames in the QFontDatabase. This happens when the render method on the QSvgRenderer is executed.
    Below is a copy of some of the error when using the library from java output:
    "Problematic frame:
    C [libQtGui.so.4+0x3ef16b] QFontDatabase::parseFontName(QString const&, QString&, QString&)+0x21b "

    I then added a local variable in the c++ library method where the i am rendering the svg as follows, in order to locate the problem:
    @QFontDatabase fdb ;
    QFont font = fdb.font("Arial","bold",9);
    qDebug() << "C++ API: font rawname:" + font.family() ;@

    When using the c++ library with above code through the Qt application, it works 100%.
    When using the c++ library from java, it falls over exactly when trying to contruct the QFontDatabase above.

    All i can think, what the problem is, is that somehow, somewhere "pre initialasing" stuff is happening for the QFontDatabase when using it from the Qt application, and not the same stuff "happened" when using the library from java?
    It looks like the QFontDatabase code rezides in the libQtGui.so.4 library, maybe i have to do additional calls in my c++ library to get the QFontDatabase to construct correctly?
    I have a feeling/suspision that something in QtGui have to be initialsed for the QFontDatabase, to work correctly when the c++ library is called from java or any other language, but i have no idea what?

    The svg file is very simple it looks like this:
    <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
    <svg width="400px" height="400px" viewBox="0 0 400 400" id="S-GPUC----*****">
    <g id="group_scale" transform="scale(1)">
    <g>
    <text x="200" y="232" >CBT</text>
    </g>
    </g>
    </svg>

    Any svg document with a text element in, let the application crash with:
    "Problematic frame:
    C [libQtGui.so.4+0x3ef16b] QFontDatabase::parseFontName(QString const&, QString&, QString&)+0x21b"

    All other svg documents without text elements renders correctly.

    Any help or suggestions will be highly appreciated.
    Thank you in advance.

    PS.
    I am using the following:
    Qt Creator 2.1.0
    Based on Qt 4.7.2 (64 bit)

    Operating System:
    Ubuntu 11.04 64bit

    1 Reply Last reply
    0
    • T Offline
      T Offline
      theunsheydenrych
      wrote on last edited by
      #2

      I found the problem.
      The SVG rendering part wants to get the "Arial" font from the QFontDatabase, and the QFontDatabase is not initialized. QFontDatabase is part of the QApplication, and QApplication handles the initialization of these things, according to the help on this page.
      http://qt-project.org/doc/qt-4.8/QApplication.html#details

      And i quote:
      QApplication's main areas of responsibility are:
      It initializes the application with the user's desktop settings such as palette(), font() and doubleClickInterval(). It keeps track of these properties in case the user changes the desktop globally, for example through some kind of control panel.

      The solution:
      Add a method to the library to initialize QApplication.

      @SYMGENAPISHARED_EXPORT void initLibrary()
      {
      QCoreApplication *app = QApplication::instance();
      if(app == NULL)
      {
      app = new QApplication(0,NULL);
      }
      }@

      The problem now is how do you release the memory when the shared library is not used any more?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved