title: Instantialize QApplication outside main function (library)
body: <p>I have a c++ library and I plan to add a optional feature to it (enabled by a macro) to show some extra debugging information. The idea is to create and open a window made with Qt to display some data. My problem is that I don't have access to the main function (it is a library) so I can't create the <code>QApplication</code> object Qt needs. I have tried creating global objects like this:</p>
  
  <pre><code>static int argc = 1;
  static char argv[1][6] = {"myapp"};
  static QApplication app(argc, (char**)argv);
  </code></pre>
  
  <p>It works but crashes at exit (on <code>~QApplication()</code>).</p>
  
  <p>Another option would be allocate the object on heap and have new API methods to initialize/finalize the library. But I don't want to change the API at all.</p>
  
  <p>Yet another would be allocate on heap on the first time I need to open a window and just leak it. But doesn't seems like a good idea.</p>
  
  <p>Any ideas?</p>
  
  <p>I'm using Qt 5.1 with GCC 4.8 targeting Windows and Linux.</p>