Maybe a library linking bug



  • Hello everyone!
    I'm developing a library set. There are 4 libraries, let's call them libA, libB, libC and libD. B, C and D depends on A. D also depends on C.
    So, when I'm running an example application which uses libA, everything is fine. But if I try using some classes from libB (or C, or D) the application crashes instantly after being launched.
    I'm having this issue with Qt5 only. With Qt4 everything works fine. The OS is Ununtu 12.04. The project's sources are here: https://github.com/the-dark-angel/BeQt/tree/develop (the "develop" branch).
    So, what do?



  • I've found the source of my problem. When using Qt5, the initialization order is different from that when using Qt4. For example, look at the following code:
    @//a.h
    class A
    {
    public:
    A() {}
    static const QFont Font;
    static QFont createFont();
    };

    //a.cpp
    const QFont A::Font = A::createFont();

    QFont A::createFont()
    {
    QFont fnt = QApplication::font();
    fnt.setPointSize(15);
    return fnt;
    }@
    It will work fine when Qt4 is used, but you'll get an application crash with Qt5. (The class must be part of a library, of course) Seems like the QtCore and/or QtGui libraries are not loaded when the QApplication::font() method is called.
    I had several places in my code where such a variable initialization technique was used. After removing them, I was able to launch my test application normally. I found out the source of problem using Valgrind (the initializing static method was mentioned in the output).
    Hope this will be helpful.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.