Important: Please read the Qt Code of Conduct -

Using wrapped Qt segfaults on Linux with only a basic example

  • I posted this exact thing on Stack Overflow, but then I thought I would have better luck here.

    I've been experimenting with wrapping some Qt classes with a C interface to use with my latest D project. For what ever reason, this code works fine on Windows but segfaults on Linux and I haven't been able to track down the reason behind it. I haven't tried building on OSX yet.

    I'm using Qt 5.3, and running Linux Mint.

    The code is kind of spread out over a few different files so I thought it might be easier if I put all the related code into some pastebins.

    "QApplication wrapper stuff":

    "QMainQWindow wrapper stuff":

    These are very thin wrappers though, so even if you don't look at them it should be easy enough to understand my test program.

    @#include <Application.h>
    #include <MainWindow.h>

    int main( int argc, char* argv[])

    Qt_Application* app = Qt_Application_create(argc, argv);
    Qt_MainWindow* window = Qt_MainWindow_create();
    Qt_MainWindow_show(window);//<- Segfault happens here
    return 0;


    Due to some printf tests, I know the segfault happens on when I try to call Qt_MainWindow_show, and likewise I know the window object exists when I pass it so that isn't the cause. Also, if I comment Qt_MainWindow_show out, Qt_Application_exec will get called no problem so as far as I know the wrapped objects are being created correctly.

    When I run gdb, it says:

    bq. Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff789a92a in strlen () from /lib/x86_64-linux-gnu/

    getting the backtrace at the point of the segfault shows this:

    bq. #0 0x00007ffff789a92a in strlen () from /lib/x86_64-linux-gnu/
    #1 0x00007ffff6b6c6bc in QCoreApplication::arguments() ()
    from /home/jebbs/Qt/5.3/gcc_64/lib/
    #2 0x00007ffff1470213 in ?? ()
    from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/
    #3 0x00007ffff14705f9 in ?? ()
    from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/
    #4 0x00007ffff147d127 in ?? ()
    from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/
    #5 0x00007ffff1470009 in ?? ()
    from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/
    #6 0x00007ffff5d47e03 in QWindow::create() ()
    from /home/jebbs/Qt/5.3/gcc_64/lib/
    #7 0x00007ffff716b97a in QWidgetPrivate::create_sys(unsigned long long, bool, bool) () from /home/jebbs/Qt/5.3/gcc_64/lib/
    #8 0x00007ffff714e6f5 in QWidget::create(unsigned long long, bool, bool) ()
    from /home/jebbs/Qt/5.3/gcc_64/lib/
    #9 0x00007ffff71512ea in QWidget::setVisible(bool) ()
    from /home/jebbs/Qt/5.3/gcc_64/lib/
    #10 0x00007ffff7bd8205 in Qt_MainWindow_show ()
    from /home/jebbs/Documents/projects/HeliosCTest/
    #11 0x0000000000400922 in main (argc=1, argv=0x7fffffffe158) at main.cpp:22 <-actually points to Qt_MainWindow_show(window), but this is from a test with printf's in it

    So it looks like some string somewhere is NULL and strlen cries? I couldn't find any reason that might segfault. Any pointers into where I should look or what I should do next would be an excellent help.

Log in to reply