title: Using wrapped Qt segfaults on Linux with only a basic example
body: <p>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.</p>
  
  <p>I'm using Qt 5.3, and running Linux Mint.</p>
  
  <p>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.</p>
  
  <p><a href="http://pastebin.com/2bzm27e8" rel="nofollow">QApplication Wrapper Stuff</a></p>
  
  <p><a href="http://pastebin.com/hsiM6Rxy" rel="nofollow">QMainWindow Wrapper Stuff</a></p>
  
  <p>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. </p>
  
  <pre><code>#include &lt;Application.h&gt;
  #include &lt;MainWindow.h&gt;
  
  int main( int argc, char* argv[])
  {
  
      Qt_Application* app = Qt_Application_create(argc, argv);
  
      Qt_MainWindow* window = Qt_MainWindow_create();
  
      Qt_MainWindow_show(window);//&lt;- Segfault happens here
  
      Qt_Application_exec(app);
  
      Qt_Application_destroy(app);
  
      Qt_MainWindow_destroy(window);
  
      return 0;
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>When I run gdb, it says:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff789a92a in strlen () from /lib/x86_64-linux-gnu/libc.so.6
  </code></pre>
  
  <p>getting the backtrace at the point of the segfault shows this:</p>
  
  <pre><code>#0  0x00007ffff789a92a in strlen () from /lib/x86_64-linux-gnu/libc.so.6
  #1  0x00007ffff6b6c6bc in QCoreApplication::arguments() ()
     from /home/jebbs/Qt/5.3/gcc_64/lib/libQt5Core.so.5
  #2  0x00007ffff1470213 in ?? ()
     from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/libqxcb.so
  #3  0x00007ffff14705f9 in ?? ()
     from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/libqxcb.so
  #4  0x00007ffff147d127 in ?? ()
     from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/libqxcb.so
  #5  0x00007ffff1470009 in ?? ()
     from /home/jebbs/Qt/5.3/gcc_64/plugins/platforms/libqxcb.so
  #6  0x00007ffff5d47e03 in QWindow::create() ()
     from /home/jebbs/Qt/5.3/gcc_64/lib/libQt5Gui.so.5
  #7  0x00007ffff716b97a in QWidgetPrivate::create_sys(unsigned long long, bool, bool) () from /home/jebbs/Qt/5.3/gcc_64/lib/libQt5Widgets.so.5
  #8  0x00007ffff714e6f5 in QWidget::create(unsigned long long, bool, bool) ()
     from /home/jebbs/Qt/5.3/gcc_64/lib/libQt5Widgets.so.5
  #9  0x00007ffff71512ea in QWidget::setVisible(bool) ()
     from /home/jebbs/Qt/5.3/gcc_64/lib/libQt5Widgets.so.5
  #10 0x00007ffff7bd8205 in Qt_MainWindow_show ()
     from /home/jebbs/Documents/projects/HeliosCTest/libqtcl.so.1
  #11 0x0000000000400922 in main (argc=1, argv=0x7fffffffe158) at main.cpp:22 &lt;-actually points to Qt_MainWindow_show(window), but this is from a test with printf's in it
  </code></pre>
  
  <p>So it looks like some string somewhere is NULL and strlen cries? I couldn't find any reason that QMainWindow.show() might segfault. Any pointers into where I should look or what I should do next would be an excellent help.</p>