title: Obtaining command line arguments in a Qt application
body: <p>The following snippet is from a little app I wrote using the Qt framework. The idea is that the app can be run in batch mode (i.e. called by a script) or can be run interactively. </p>
  
  <p>It is important therefore, that I am able to parse command line arguments in order to know which mode in which to run etc.</p>
  
  <p><strong>[Edit]</strong></p>
  
  <p>I am debugging using Qt Creator 1.3.1 on Ubuntu Karmic. The arguments are passed in the normal way (i.e. by adding them via the 'Project' settings in the Qt Creator IDE). </p>
  
  <p>When I run the app, it appears that the arguments are not being passed to the application. The code below, is a snippet of my main() function. </p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      //Q_INIT_RESOURCE(application);
  
      try {
          QApplication the_app(argc, argv);
  
          //trying to get the arguments into a list    
          QStringList cmdline_args = QCoreApplication::arguments();
  
          // Code continues ...
      }
      catch (const MyCustomException &amp;e) { return 1; }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>[Update]</strong></p>
  
  <p>I have identified the problem - for some reason, although argc is correct, the elements of argv are empty strings.</p>
  
  <p>I put this little code snippet to print out the argv items - and was horrified to see that they were all empty.</p>
  
  <pre><code>for (int i=0; i&lt; argc; i++){
      std::string s(argv[i]); //required so I can see the damn variable in the debugger
      std::cout &lt;&lt; s &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Does anyone know how I can retrieve the command line args in my application?</p>