title: "Must construct a QApplication before a QWidget"
body: <p>I'm trying to make a simple Qt program.I have successfully build and run the program several times.These errors occurred when I added a getter method to pass a string from my MainWindow to a dialog's <code>QFileDialog::getSaveFileName()</code> But when I comment below lines the programs runs successfully.<br>
  <strong>MainWindow.h</strong></p>
  
  <pre><code>class MainWindow : public QMainWindow
  {
      Q_OBJECT
      public:
      QString fileName();
  };
  </code></pre>
  
  <p><strong>MainWindow.cpp</strong></p>
  
  <pre><code>QString MainWindow::fileName() {
      return "F:/Users/Admin/Desktop/" + dnldName;
  }
  </code></pre>
  
  <p><strong>Usage of fileName()</strong></p>
  
  <pre><code>void Dialog::on_browseButton_clicked()
  {
      QFileDialog folder;
      folder.setFileMode(QFileDialog::Directory);
      folder.setOption(QFileDialog::ShowDirsOnly);
      dirPath = folder.getSaveFileName(this, tr("Save File"), mWinObj.fileName(), tr("All Files"));
      ui-&gt;savePathEdit-&gt;setText(dirPath);
  }
  </code></pre>
  
  <p>The program builds successfully but gives the following errors when I try to run it.  </p>
  
  <pre><code>Starting F:\Users\Admin\Desktop\Imp Docs\C++ apps\build-GUINetworkApp-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\GUINetworkApp.exe...
  QWidget: Must construct a QApplication before a QWidget
  Invalid parameter passed to C runtime function.
  Invalid parameter passed to C runtime function.
  F:\Users\Admin\Desktop\Imp Docs\C++ apps\build-GUINetworkApp-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\GUINetworkApp.exe exited with code 3   
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include "mainwindow.h"
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
  
      return a.exec();
  }
  </code></pre>
  
  <p>What's wrong with the code and how can I fix it?</p>