Results 1 to 4 of 4

Thread: segment fault with any QT GUI program

  1. #1
    Join Date
    Dec 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default segment fault with any QT GUI program

    Hi,all:
    Now,I cross-compile QT 4.6.0 for arm(LPC3250),and now I meet a strange segment fault when I try to run a GUI program (even "hello world").
    Here is my hello.cpp:
    Qt Code:
    1. #include<QtGui>
    2. int main(int argc,char * argv[])
    3. {
    4. QApplication app(argc,argv);
    5. QLabel label("hello world\n");
    6. label.show();
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    When I gdb the core file,I got this:
    Qt Code:
    1. #0 0x407a327c in qt_getFreetypeData () at text/qfontengine_ft.cpp:142
    2. #1 0x407a530c in qt_getFreetype () at text/qfontengine_ft.cpp:156
    3. #2 0x40656a0c in QFontDatabasePrivate::addTTFile (this=0x155e8, file=...,
    4. fontData=...) at text/qfontdatabase.cpp:779
    5. #3 0x40659054 in initializeDb () at text/qfontdatabase_qws.cpp:362
    6. #4 0x4065d320 in qt_qws_init_fontdb () at text/qfontdatabase_qws.cpp:506
    7. #5 0x401c4d58 in QWSServerPrivate::initServer (this=0x15d38, flags=0)
    8. at embedded/qwindowsystem_qws.cpp:1422
    9. #6 0x401c5254 in QWSServer::QWSServer (this=0x13948, flags=0, parent=0x0)
    10. at embedded/qwindowsystem_qws.cpp:1301
    11. #7 0x401c5434 in QWSServer::startup (flags=0)
    12. at embedded/qwindowsystem_qws.cpp:4067
    13. #8 0x40321cc4 in qt_init (priv=0x12b58, type=2)
    14. at kernel/qapplication_qws.cpp:2303
    15. #9 0x402365d8 in QApplicationPrivate::construct (this=0x12b58)
    16. at kernel/qapplication.cpp:768
    17. #10 0x402378cc in QApplication::QApplication (this=0xbefebdcc,
    18. argc=@0xbefebdb0, argv=0xbefebe64, _internal=263680)
    19. at kernel/qapplication.cpp:690
    20. #11 0x00008a30 in main (argc=1, argv=0xbefebe64) at hello.cpp:4
    To copy to clipboard, switch view to plain text mode 
    It seems the segment fault occurred in qt_getFreetypeData () at text/qfontengine_ft.cpp:142
    And then,I add printf in qt_getFreetypeData () at text/qfontengine_ft.cpp:142 to see why it's segment fault.
    The original qt_getFreetypeData () is like that:
    Qt Code:
    1. QtFreetypeData *qt_getFreetypeData()
    2. {
    3. QtFreetypeData *&freetypeData = theFreetypeData()->localData();
    4. if (!freetypeData)
    5. freetypeData = new QtFreetypeData;
    6. return freetypeData;
    7. }
    To copy to clipboard, switch view to plain text mode 
    After modified qt_getFreetypeData () is like that:
    Qt Code:
    1. QtFreetypeData *qt_getFreetypeData()
    2. {
    3. QtFreetypeData *&freetypeData = theFreetypeData()->localData();
    4. if (!freetypeData)
    5. {
    6. printf("%s\n",__func__);
    7. freetypeData = new QtFreetypeData;
    8. }
    9. return freetypeData;
    10. }
    To copy to clipboard, switch view to plain text mode 
    After rebuild all,I still got a segment fault.But this time when I gdb core, I got this:
    Qt Code:
    1. #0 0x4061a768 in QFontCache::instance () at text/qfont.cpp:2589
    2. #1 0x40620014 in QFontPrivate::engineForScript (this=0x36f08, script=0)
    3. at text/qfont.cpp:264
    4. #2 0x40646920 in QFontMetrics::height (this=0xbe8291f8)
    5. at text/qfontmetrics.cpp:329
    6. #3 0x4090deb4 in QPlastiqueStyle::pixelMetric (this=0x37088,
    7. metric=QStyle::PM_TitleBarHeight, option=0xbe8291d8, widget=0x0)
    8. at styles/qplastiquestyle.cpp:5611
    9. #4 0x401f0060 in QDecorationStyled::titleBarHeight (this=0x36810,
    10. widget=0xbe829db8) at embedded/qdecorationstyled_qws.cpp:84
    11. #5 0x401eb8d8 in QDecorationDefault::region (this=0x36810,
    12. widget=0xbe829db8, rect=..., decorationRegion=2147483647)
    13. at embedded/qdecorationdefault_qws.cpp:421
    14. #6 0x401ef9f0 in QDecorationStyled::region (this=0x36810,
    15. widget=0xbe829db8, rect=..., decorationRegion=2147483647)
    16. at embedded/qdecorationstyled_qws.cpp:298
    17. #7 0x4033694c in QWidgetPrivate::create_sys (this=0x33e40, window=0,
    18. initializeWindow=true) at kernel/qwidget_qws.cpp:222
    19. #8 0x402d95ec in QWidget::create (this=0xbe829db8, window=0,
    20. initializeWindow=true, destroyOldWindow=true) at kernel/qwidget.cpp:1318
    21. #9 0x402db47c in QWidget::setVisible (this=0xbe829db8, visible=true)
    22. at kernel/qwidget.cpp:7329
    23. #10 0x00008c74 in QWidget::show (this=0xbe829db8)
    24. at ../qt-lib/include/QtGui/qwidget.h:481
    25. #11 0x00008ae8 in main (argc=1, argv=0xbe829e64) at hello.cpp:6
    26. It seems that,when I add the printf in qt_getFreetypeData () at text/qfontengine_ft.cpp:142,
    To copy to clipboard, switch view to plain text mode 
    It did not meet a segment fault in qt_getFreetypeData (),but meet segment fault after.

    Now the strange thing is:
    Not add printf in qt_getFreetypeData (),segment fault occurred in main->QApplication app(argc,argv)->...->qt_getFreetypeData () at text/qfontengine_ft.cpp:142
    Add printf in qt_getFreetypeData (), segment fault occurred in main->label.show()->QFontCache::instance () at text/qfont.cpp:2589

    I guess it is cause by Compiler optimization.
    So instead of add printf, I add memory barrier in qt_getFreetypeData () to avoid wrong optimization.
    Now the qt_getFreetypeData() is like this:
    Qt Code:
    1. QtFreetypeData *qt_getFreetypeData()
    2. {
    3. QtFreetypeData *&freetypeData = theFreetypeData()->localData();
    4. if (!freetypeData)
    5. {
    6. // printf("%s\n",__func__);
    7. __asm__ __volatile__("":::"memory");
    8. freetypeData = new QtFreetypeData;
    9. }
    10. return freetypeData;
    11. }
    To copy to clipboard, switch view to plain text mode 
    But it is useless,it still occur segment fault in qt_getFreetypeData.

    Then,I check the QFontCache::instance () at text/qfont.cpp:2589 because it cause the other segment fault.
    And I found that the instance() is similar to qt_getFreetypeData().
    The instance() is like this:
    Qt Code:
    1. QFontCache *QFontCache::instance()
    2. {
    3. QFontCache *&fontCache = theFontCache()->localData();
    4. if (!fontCache)
    5. fontCache = new QFontCache;
    6. return fontCache;
    7. }
    To copy to clipboard, switch view to plain text mode 
    So I add printf() in instance too,like this:
    Qt Code:
    1. QFontCache *QFontCache::instance()
    2. {
    3. QFontCache *&fontCache = theFontCache()->localData();
    4. if (!fontCache)
    5. {
    6. printf("%s\n",__func__);
    7. fontCache = new QFontCache;
    8. }
    9. return fontCache;
    10. }
    To copy to clipboard, switch view to plain text mode 
    After add printf() in both qt_getFreetypeData() and instance(),rebuild all,no segment fault occur and i can see "hello world" on my board.
    Now I want to know how can I solve segment fault without adding printf()?

    This thread is so long ,thanks for read it.

    Environment:

    Host OS is fedora 10.

    cross-compiler:
    Qt Code:
    1. [ljp@localhost hello]$ arm-vfp-linux-gnu-gcc -v
    2. Using built-in specs.
    3. Target: arm-vfp-linux-gnu
    4. Configured with: /home/usb10132/ct1/bin/targets/src/gcc-4.3.2/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-vfp-linux-gnu --prefix=/home/usb10132/x-tools/arm-vfp-linux-gnu --with-sysroot=/home/usb10132/x-tools/arm-vfp-linux-gnu/arm-vfp-linux-gnu/sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv5te --with-abi=atpcs --with-cpu=arm926ej-s --with-fpu=vfp --with-float=soft --with-gmp=/home/usb10132/x-tools/arm-vfp-linux-gnu --with-mpfr=/home/usb10132/x-tools/arm-vfp-linux-gnu --with-pkgversion=crosstool-NG-1.3.1 --enable-__cxa_atexit --with-local-prefix=/home/usb10132/x-tools/arm-vfp-linux-gnu/arm-vfp-linux-gnu/sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
    5. Thread model: posix
    6. gcc version 4.3.2 (crosstool-NG-1.3.1)
    To copy to clipboard, switch view to plain text mode 


    qmake.conf:
    Qt Code:
    1. #
    2. # qmake configuration for building with arm-linux-g++
    3. #
    4.  
    5. include(../../common/g++.conf)
    6. include(../../common/linux.conf)
    7. include(../../common/qws.conf)
    8.  
    9. # modifications to g++.conf
    10. QMAKE_CC = arm-vfp-linux-gnu-gcc
    11. QMAKE_CXX = arm-vfp-linux-gnu-g++
    12. QMAKE_LINK = arm-vfp-linux-gnu-g++
    13. QMAKE_LINK_SHLIB = arm-vfp-linux-gnu-g++
    14.  
    15. # modifications to linux.conf
    16. QMAKE_AR = arm-vfp-linux-gnu-ar cqs
    17. QMAKE_OBJCOPY = arm-vfp-linux-gnu-objcopy
    18. QMAKE_STRIP = arm-vfp-linux-gnu-strip
    19.  
    20. load(qt_config)
    To copy to clipboard, switch view to plain text mode 

    QT configure script
    Qt Code:
    1. ./configure -embedded arm -xplatform qws/linux-m3250 -prefix /home/ljp/qt-lib\
    2. -qt-mouse-tslib -I/home/ljp/tslib-lib/include -L/home/ljp/tslib-lib/lib\
    3. -nomake examples -nomake demos -no-webkit \
    4. -no-exceptions -debug -qt-zlib \
    5. -no-largefile -no-accessibility -no-stl -no-qt3support -no-xmlpatterns -no-phonon -no-phonon-backend \
    6. -no-multimedia -no-javascript-jit -no-openssl -nomake docs -nomake translations -nomake tools -no-nis \
    7. -no-pch -no-libtiff -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xkb -no-sm -no-xinerama -no-xshape \
    8. -optimized-qmake -no-opengl -no-separate-debug-info -no-qvfb -qt-gfx-linuxfb -no-gfx-qvfb -no-kbd-qvfb \
    9. -opensource -confirm-license -no-scripttools -no-cups -no-mouse-qvfb
    To copy to clipboard, switch view to plain text mode 

    I build hello like this :
    qmake -project
    qmake
    make

    Target board is LPC3250,it has a VFP.

    I have read the thread:
    http://www.qtcentre.org/threads/2323...debug-quot-Qt-!
    And do what it said(except change the compiler),but all useless.
    can anyone help me?
    Thanks again.

  2. #2
    Join Date
    Dec 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: segment fault with any QT GUI program

    Hi all,now I found another things:
    when I add
    Qt Code:
    1. char ch[]={'a','b'};
    To copy to clipboard, switch view to plain text mode 
    instead of printf(),
    The GUI program works too.
    Any one know why?

  3. #3
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: segment fault with any QT GUI program

    Hi, I got the same symptoms !

    I'll try your solution, but did you find a better solution, or an explanation for this problem ?

    Processor is ARM926EJ-S rev 5 (v5l) (arm9 iMX233), and I have the same problem on another arm9 : ARM920T rev 0 (v4l) (Samsung S3C2442B)

    I'm using gcc from emdebian ([...] --target=arm-linux-gnueabi [...] gcc version 4.4.5 (Debian 4.4.5-8))

    I will try adding
    QMAKE_CFLAGS += -march=armv5te
    QMAKE_CXXFLAGS += -march=armv5te
    to my specs, as the same binaries are running just fine on an armv6 (arm11 - iMX353)

    (compilation of Qt libs running right now ...)

  4. #4
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: segment fault with any QT GUI program

    Back, and with a much better solution: sitch to Qt 4.7.2 !

    First, I found some interesting info there :
    QTBUG-14804
    and there :
    QTBUG-13441

    I seems that the freetype implementation embedded in Qt has problems with ARM9 cores.

    But I tried to use -system-freetype in configure with no success.
    But the bug reports also mentioned that the problems where in 4.7.0 and 4.7.1, but not 4.7.2.
    So I tried 4.7.2, and I have no more segfault.

    If you're interrested in the reasons behind the segfaults, look at the bugreports and the solution, I did not have time for this.

    +++
    have fun !

Similar Threads

  1. Draw directly from a memory segment
    By 25an in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2009, 13:04
  2. Segmentation Fault when Program Starts
    By KaptainKarl in forum Newbie
    Replies: 7
    Last Post: 10th September 2009, 08:43
  3. Segment fault using a Qt plugin with QTabWidget
    By tarod in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2009, 10:27
  4. Segment fault when using Q3ListBox and QFile
    By hiuao in forum Qt Programming
    Replies: 8
    Last Post: 12th May 2007, 11:51
  5. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 16:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.