title: Parent and Child Window Communication in Qt - Child Window opens twice
body: <p>I have two windows, one parent and one child. In parent window, I have a Next button, which onClick()'ed, opens up child window, but in my case two child windows are opening, what is the mistake am doing!?</p>
  
  <p>Here are my codes:</p>
  
  <p><strong>.h files</strong></p>
  
  <p><em>mainwindow.h</em></p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;info.h&gt;
  #include &lt;QtGui&gt;
  
  namespace Ui {
      class MainWindow;
  }
  
  class MainWindow : public QMainWindow {
      Q_OBJECT
  public:
      MainWindow(QWidget *parent = 0);
      ~MainWindow();
  
  protected:
      void changeEvent(QEvent *e);
  
  private:
      Ui::MainWindow *ui;
      void setSignals();
  
  private slots:
      void process();
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p><em>info.h</em></p>
  
  <pre><code>#ifndef INFO_H
  #define INFO_H
  
  #include &lt;QMainWindow&gt;
  
  namespace Ui {
      class info;
  }
  
  class info : public QMainWindow {
      Q_OBJECT
  public:
      info(QWidget *parent = 0);
      ~info();
  
  protected:
      void changeEvent(QEvent *e);
  
  private:
      Ui::info *ui;
  };
  
  #endif // INFO_H
  </code></pre>
  
  <p><strong>.cpp files</strong></p>
  
  <p><em>mainwindow.cpp</em></p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QtGui/QApplication&gt;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      setSignals();
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::changeEvent(QEvent *e)
  {
      QMainWindow::changeEvent(e);
      switch (e-&gt;type()) {
      case QEvent::LanguageChange:
          ui-&gt;retranslateUi(this);
          break;
      default:
          break;
      }
  }
  
  void MainWindow::setSignals(){
      connect(ui-&gt;pushButton,SIGNAL(clicked()),this,SLOT(process()));
      connect(ui-&gt;pushButton_2,SIGNAL(clicked()),this,SLOT(close()));
  }
  
  void MainWindow::process(){
          info *i;
          i = new info;
          this -&gt; hide();
          i -&gt; show();
  }
  </code></pre>
  
  <p><em>info.cpp</em></p>
  
  <pre><code>#include "info.h"
  #include "ui_info.h"
  
  info::info(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::info)
  {
      ui-&gt;setupUi(this);
  }
  
  info::~info()
  {
      delete ui;
  }
  
  void info::changeEvent(QEvent *e)
  {
      QMainWindow::changeEvent(e);
      switch (e-&gt;type()) {
      case QEvent::LanguageChange:
          ui-&gt;retranslateUi(this);
          break;
      default:
          break;
      }
  }
  </code></pre>
  
  <p><em>main.cpp</em></p>
  
  <pre><code>#include &lt;QtGui/QApplication&gt;
  #include "mainwindow.h"
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
      return a.exec();
  }
  </code></pre>