I am very much new to Qt and I have a simple doubt on switching between the windows.

I have a main window and I am creating a secondary window using a different class. I am hiding the primary window using hide( ) function and only the second window belonging to different class is visible. When the user presses the close button I have to show back the first window. My code looks something like this.

main.cpp
Qt Code:
  1. #include "FirstWindow.h"
  2. int main(int argc, char *argv[])
  3. {
  4. QApplication a(argc, argv);
  5. FirstWindow w;
  6.  
  7. w.setAttribute( Qt :: WA_QuitOnClose );
  8. w.show();
  9. return a.exec();
  10. }
To copy to clipboard, switch view to plain text mode 

Important lines belonging to FirstWindow.h.
Qt Code:
  1. #include "SecondWindow.h"
  2. class FirstWindow : public QDialog
  3. {
  4. Q_OBJECT
  5.  
  6. private:
  7.  
  8. SecondWindow * window2;
  9.  
  10. public:
  11. void some_function( ){
  12.  
  13. this -> hide( );
  14. window2 = new SecondWindow( );
  15. window2 -> displayTheWindow( );
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

Important lines belonging to SecondWindow.h

Qt Code:
  1. class SecondWindow : public QDialog
  2. {
  3. Q_OBJECT
  4.  
  5. private:
  6.  
  7. QDialog * dialog;
  8.  
  9. public slot:
  10.  
  11. void startFirstWindow( );
  12.  
  13. public:
  14. SecondWindow( ){
  15. dialog = new QDialog( );
  16. connect( this, SIGNAL( rejected( ) ), this, SLOT( startFirstWindow( ) ) );
  17. }
  18. }
To copy to clipboard, switch view to plain text mode 


Can anybody please help me how should I write the slot of startFirstWindow( ). I just want to make the first window visible again. Or is there another approach to this without much changes.

Thanks in advance for the help.