Hello everybody . I'm new to this forum ( because it's the first time for me using QT but i'm pretty sure i'll be using it regularly from now ) . I followed a couple of tutorials, wrote some simple GUI applications but I could'nt find an answer for my problem .

I have to ui's ( dlg1.ui and dlg2.ui ). dlg1.ui is the main window of my application(project type: MainWindow) , with the name Form1 , and dlg2.ui is another window( project type Widget ) .

Here is how my projects files look like .
main.cpp
Qt Code:
  1. #include <qapplication>
  2. #include "app.h"
  3.  
  4. int main(int argc,char *argv[])
  5. {
  6. QApplication app(argc,argv);
  7. App1 dialog;
  8. dialog.show();
  9. return app.exec();
  10. }
To copy to clipboard, switch view to plain text mode 

app.h
Qt Code:
  1. #ifndef APP_H
  2. #define APP_H
  3.  
  4. #include "ui_dlg1.h"
  5. #include "ui_dlg2.h"
  6.  
  7. class App1:public QMainWindow,private Ui::Form1
  8. {
  9. Q_OBJECT
  10. public:
  11. App1();
  12. public slots:
  13. void button_clicked();
  14. };
  15.  
  16. class App2:public QWidget,private Ui::Form2
  17. {
  18. Q_OBJECT
  19. public:
  20. App2(QWidget *parent = 0);
  21. };
  22.  
  23. #endif
To copy to clipboard, switch view to plain text mode 
app.cpp
Qt Code:
  1. #include <QtGui>
  2. #include "app.h"
  3.  
  4. App1::App1()
  5. {
  6. setupUi(this);
  7. connect(pushButton,SIGNAL(clicked()),this,SLOT(button_clicked()));
  8. }
  9.  
  10. App2::App2(QWidget *parent)
  11. {
  12. setupUi(this);
  13. }
  14.  
  15. void App1::button_clicked()
  16. {
  17. App2 form2(this);
  18. form2.show();
  19. }
To copy to clipboard, switch view to plain text mode 

This code works just fine but when I press the button , Form2 appears for a very very short time and then it's being destroyed . Why this happens ? And how can I correct it so that Form2 shows as a modal window ( no interraction with Form1 being possible till Form2 is being closed ) .

Furthermore, how can I make two forms communicate with each other ? My idea was a global variabiles in app.cpp that each form can see .

I hope I was clear enough . Have a great day !