I am trying to learn QT creator and have searched and read the forum and several other areas but I must be missing something. I am writing a program that will have a main window and then widgets (dialog forms) that I want to open and close inside the main window. I am able to create the forms and have a button open the second form. The problem is that the form does not open as a child of the main window. I think I might need to create some sort of container in the main form and pass a pointer to that container? I am lost at how to do this. I am using QT Creator 1.2.1 based on QT 4.5.2. What am I missing? Here is the code!

MainWindow.h

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class MainWindow;
  8. }
  9.  
  10. class MainWindow : public QMainWindow
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit MainWindow(QWidget *parent = 0);
  16. ~MainWindow();
  17.  
  18. protected:
  19. void changeEvent(QEvent *e);
  20.  
  21. private:
  22. Ui::MainWindow *ui;
  23.  
  24. private slots:
  25. void on_btnNextPage_clicked(); //Identify a pointer here? Buy how?
  26.  
  27. };
To copy to clipboard, switch view to plain text mode 
MainWindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "page2.h"
  4.  
  5. MainWindow::MainWindow(QWidget *parent) :
  6. QMainWindow(parent),
  7. ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10. }
  11.  
  12. MainWindow::~MainWindow()
  13. {
  14. delete ui;
  15. }
  16.  
  17. void MainWindow::changeEvent(QEvent *e)
  18. {
  19. QMainWindow::changeEvent(e);
  20. switch (e->type()) {
  21. case QEvent::LanguageChange:
  22. ui->retranslateUi(this);
  23. break;
  24. default:
  25. break;
  26. }
  27. }
  28.  
  29. void MainWindow::on_btnNextPage_clicked()
  30. {
  31.  
  32. Page2* page2 = new Page2 () ; // Page2* page2 = new Page2 (this) ; ??
  33. page2->exec();
  34. }
To copy to clipboard, switch view to plain text mode