Segmentation fault on dummy app



  • Hi,

    My program exits with a segmentation fault and I don't know why ...

    #include <QApplication>
    #include <QTimer>
    #include <QDebug>
     
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
     
        QTimer::singleShot( 2000, &app, SLOT( quit() ) );
     
        qDebug() << "app.exec() return code :" << app.exec();
    }
    

    The printed messages are :

    app.exec() return code : 0
    *** Error in `./sans_titre': free(): invalid pointer: 0x6bd00040 ***
    Aborted
    
    

    Where is the problem ?

    I run it on an imx6 board using a yocto environment (jethro branch).
    My conf :

    MACHINE ?= 'apalis-imx6'
    DISTRO ?= 'poky'
    PACKAGE_CLASSES ?= "package_rpm"
    EXTRA_IMAGE_FEATURES = "debug-tweaks ssh-server-openssh"
    USER_CLASSES ?= "buildstats image-mklibs"
    PATCHRESOLVE = "noop"
    BB_DISKMON_DIRS = "\
        STOPTASKS,${TMPDIR},1G,100K \
        STOPTASKS,${DL_DIR},1G,100K \
        STOPTASKS,${SSTATE_DIR},1G,100K \
        STOPTASKS,/tmp,100M,100K \
        ABORT,${TMPDIR},100M,1K \
        ABORT,${DL_DIR},100M,1K \
        ABORT,${SSTATE_DIR},100M,1K \
        ABORT,/tmp,10M,1K"
    PACKAGECONFIG_append_pn-qemu-native = " sdl"
    PACKAGECONFIG_append_pn-nativesdk-qemu = " sdl"
    ASSUME_PROVIDED += "libsdl-native"
    CONF_VERSION = "1"
    LICENSE_FLAGS_WHITELIST = "commercial"
    
    DL_DIR ?= "${BSPDIR}/downloads/"
    
    IMAGE_INSTALL_append = " gcc g++ binutils libgcc libgcc-dev libstdc++ libstdc++-dev libstdc++-staticdev \
    autoconf automake ccache chkconfig glib-networking glibmm \
    packagegroup-core-buildessential pkgconfig  \
    boost cmake zlib glib-2.0 packagegroup-fsl-tools-testapps  \
        cpufrequtils \
        nano \
        gdb \
        openssh-sftp-server \
        imx-vpu \
        imx-test \
        firmware-imx \
        qtbase-fonts \
        qtbase-plugins \
        qtbase-tools \
        qtdeclarative \
        qtdeclarative-plugins \
        qtdeclarative-tools \
        qtdeclarative-qmlplugins \
        qtimageformats-plugins \
        qtsystems \
        qtsystems-tools \
        qtsystems-qmlplugins \
        qtgraphicaleffects-qmlplugins \
        qtconnectivity-qmlplugins \
        cairo pango fontconfig freetype pulseaudio dbus \
        i2c-tools \ 
        gstreamer1.0-plugins-imx \
        gst1.0-fsl-plugin \
        gstreamer1.0-plugins-base \
        gstreamer1.0-plugins-good \
        gstreamer1.0-plugins-good-apps \
        gstreamer1.0-plugins-base-apps \
        gstreamer1.0-libav \
        psplash \
        u-boot-toradex-fsl-fw-utils \
    "
    
    DISTRO_FEATURES_remove = "x11 wayland"
    IMAGE_INSTALL_remove = "eglinfo-x11"
    IMAGE_FEATURES += "dev-pkgs tools-debug"
    KERNEL_IMAGETYPE = "uImage"
    ACCEPT_FSL_EULA = "1"
    IMAGE_FSTYPES += "ext3"
    

    Thanks for your help...

    Regards,


  • Moderators

    @VincentB
    did you compile Qt yourself?
    Please also post the stack trace of the crash



  • @VincentB said:

    The printed messages are :

    app.exec() return code : 0
    app.exec() return code : 0
    *** Error in `./sans_titre': free(): invalid pointer: 0x6bd00040 ***
    Aborted
    

    do you really get the debug output twice when running the app once?



  • No I did a mistake when I copy/paste



  • @raven-worx ,

    Qt has been compiled by yocto.

    What steps I have to follow to have a stack trace ?



  • @VincentB
    As I see you use QApplication which is designed for GUI apps. I don't think that this is the reason but can you try to replace QApplication with QCoreApplication and repeat the test?

    Footnote: I can't reproduce the error with Qt 5.5 on Ubuntu (no crash).



  • @micland ,

    With QCoreApplication, there is no problem. What could we conclude ?



  • @VincentB said:

    With QCoreApplication, there is no problem. What could we conclude ?

    Fine - we found a solution :) But I have no idea what the problem is. QApplication inherits QGuiApplication which inherits QCoreApplication. In my opinion the child classes just add additional GUI related functionality but should not have different behaviour (and shall not have following the Liskov substitution principle).
    The documentation only says that QCoreApplication should be used for non-GUI applications because it has no dependencies to QWidgets. But there is no note that you have to use only QCoreApplication.
    Perhaps someone else here knows more about the internas of the three classes?


  • Qt Champions 2016

    @VincentB @micland
    Well,
    QCoreApplication does almost nothing - it starts an event loop, while QApplication is fat and heavy and loads plugins and platform integrations and widgety things, so it may simply be a bug. But in any case @raven-worx's request is relevant, you should obtain a stack trace from the crash (how depends on the IDE and its setup).

    Kind regards.



  • Ok,

    I''ve done this test cause on my main gui application I've got the same problem. Now, I'll search how to get a good stack trace to poste here (Unless you can advice me on how to do that).


  • Moderators

    @VincentB
    from where do you have the console output? From your IDE?
    If so there should also be a window which shows the stack trace at the time of the crash.



  • @raven-worx ,

    Hi, ok, I'll check this



  • Sorry but I'm not sure to find where to find this stack window .. (I'm using qtcreator 3.6.0)


  • Moderators

    @VincentB said:

    Sorry but I'm not sure to find where to find this stack window .. (I'm using qtcreator 3.6.0)

    see this.


Log in to reply
 

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