title: Why do we declare a namespace for the ui object in Qt when dealing with forms?
body: <p>I'm new to Qt. So when we create a new GUI project with Qt Creator the auto generated code looks like this :-</p>
  
  <pre><code>namespace Ui {
  class MainWindow;
  }
  
  
  class MainWindow : public QMainWindow
  {
  Q_OBJECT
  
  .....
  
  private:
  Ui::MainWindow *ui;
  };
  </code></pre>
  
  <p>I started looking at the code of the ui object and after going through the generated code I understood this :-
  There are 2 classes with the same name "MainWindow". One which is declared in mainwindow.h And another which is declared in "ui_mainwindow.h" i.e. Ui::MainWindow. Both of these are very different classes and the MainWindow class is not the same as the Ui::MainWindow class even though they have the same name. And this is the code in the ui_mainwidow.h :-</p>
  
  <pre><code>namespace Ui {
  class MainWindow: public Ui_MainWindow {};
  }
  </code></pre>
  
  <p>So basically the MainWindow class in the UI namespace i.e. Ui::MainWindow inherits the Ui_Mainwindow class and doesn't make any changes to it. So its basically the Ui_Mainwindow class itself.</p>
  
  <p>So my question is why do we create another class with the same name in the Ui namespace. Isn't it much easier to understand and better readable if we did not do that and create the private ui Object in the mainwindow.h file like this without creating a namespace :-</p>
  
  <hr>
  
  <pre><code>Ui_MainWindow *ui;
  </code></pre>
  
  <hr>
  
  <p>Instead of </p>
  
  <hr>
  
  <pre><code>namespace Ui {
  class MainWindow: public Ui_MainWindow {};
  }
  
  Ui::MainWindow *ui;
  </code></pre>
  
  <hr>
  
  <p>What is the drawback if any, in directly making an instance of the Ui_MainWindow class. Instead of making another class with same name in the namespace Ui, because doing so causes additional confusion as we get 2 different class with the same name. Does creating this other class have any advantages ?</p>
  
  <p><strong>EDIT :-</strong>
  One answer was "to forward declare the Ui class". But my question is can't we simply forward declare the Ui_MainWIndow class Itself instead of making the other class ?
  My main question is Y is this other class being made instead of using the Ui_MainWindow class itself?</p>