title: Qt4 Wrapper results in Segmentation fault(s)
body: <p>I'm currently writing a set of wrapper functions of Qt4 for an application as plugin (because I personally think that writing extensions in plain C is easier to accomplish).</p>
  
  <p>At first I though this could be done by simply abstracting the following:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QPushButton&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication* app = new QApplication(argc, argv);
      QPushButton* hello = new QPushButton("Hello world!");
      hello-&gt;resize(500, 300);
      hello-&gt;show();
      return app-&gt;exec();
  }
  </code></pre>
  
  <p>Into this (as a matter of fact, that's the code in main.c of my wrapper):</p>
  
  <pre><code>#include "bind.h"
  
  int main(int argc, char* argv[])
  {
      gui_application_t* app;
      gui_pushbutton_t* hello;
      app = gui_application_new(argc, argv);
      hello = gui_pushbutton_new("Hello World");
      gui_pushbutton_resize(hello, 100, 30);
      gui_pushbutton_show(hello);
      return gui_application_exec(app);
  }
  </code></pre>
  
  <p>While the former works (as expected), I'm getting segmentation faults at apparently random places in the latter. I hoped my version would just do the same as the former... but I'm afraid it doesn't at all :-(</p>
  
  <p>After running the binary, the output is usually:</p>
  
  <pre><code> *** GUI Debug: gui_application_new: ctx-&gt;app = hex_addr
   *** GUI Debug: gui_pushbutton_new: ctx-&gt;button = hex_addr
   *** GUI Debug: gui_pushbutton_resize: ctx-&gt;button = hex_addr
   *** GUI Debug: gui_pushbutton_show: ctx-&gt;button = hex_addr
  Segmentation fault
  </code></pre>
  
  <p>However, even after removing the calls to <code>gui_pushbutton_*</code> (and only calling <code>gui_application_new</code> and <code>gui_application_exec</code>), the application will still crash, but in <code>gui_application_exec</code>.</p>
  
  <p>Output from running the binary with gdb: <a href="http://codepad.org/wBifH1B2" rel="nofollow">http://codepad.org/wBifH1B2</a></p>
  
  <p>Sources: <a href="http://dl.dropbox.com/u/863332/wrapper.tar.bz2" rel="nofollow">http://dl.dropbox.com/u/863332/wrapper.tar.bz2</a></p>
  
  <p>Any help is very appreciated, as this got me very puzzled...</p>