hi all,

previously I posted a question on multiple forms handling. However no one replied. Anyway, I hope this time someone would reply me.

I am using qt creator and designer to work out my application. I have 2 forms (f1,f2) I want to load f2 when f1 button is pressed and also pass a variable to f2. How can I do it?

below is my codes. when I clicked on the button. nothing happen.

Form1.h
Qt Code:
  1. #ifndef FORM1_H
  2. #define FORM1_H
  3.  
  4. #include <QWidget>
  5.  
  6. namespace Ui {
  7. class form1;
  8. }
  9.  
  10. class form1 : public QWidget {
  11. Q_OBJECT
  12. public:
  13. form1(QWidget *parent = 0);
  14. ~form1();
  15.  
  16. protected:
  17. void changeEvent(QEvent *e);
  18.  
  19. private slots:
  20. void load_form2();
  21.  
  22. private:
  23. Ui::form1 *ui;
  24. };
  25.  
  26. #endif // FORM1_H
To copy to clipboard, switch view to plain text mode 

form1.cpp
Qt Code:
  1. #include "form1.h"
  2. #include "ui_form1.h"
  3. #include "form2.h"
  4. #include "ui_form2.h"
  5. #include <QString>
  6.  
  7. form1::form1(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::form1)
  10. {
  11. ui->setupUi(this);
  12. }
  13.  
  14. form1::~form1()
  15. {
  16. delete ui;
  17. }
  18.  
  19. void form1::changeEvent(QEvent *e)
  20. {
  21. QWidget::changeEvent(e);
  22. switch (e->type()) {
  23. case QEvent::LanguageChange:
  24. ui->retranslateUi(this);
  25. break;
  26. default:
  27. break;
  28. }
  29. }
  30.  
  31. void form1::load_form2()
  32. {
  33. QString str = "to be pass over to f2";
  34. Form2 f2;
  35. f2.show();
  36. }
To copy to clipboard, switch view to plain text mode 

from2.h
Qt Code:
  1. #ifndef FORM2_H
  2. #define FORM2_H
  3.  
  4. #include <QWidget>
  5.  
  6. namespace Ui {
  7. class Form2;
  8. }
  9.  
  10. class Form2 : public QWidget {
  11. Q_OBJECT
  12. public:
  13. Form2(QWidget *parent = 0);
  14. ~Form2();
  15.  
  16. protected:
  17. void changeEvent(QEvent *e);
  18.  
  19. private slots:
  20. void load_form1();
  21.  
  22. private:
  23. Ui::Form2 *ui;
  24. };
  25.  
  26. #endif // FORM2_H
To copy to clipboard, switch view to plain text mode 

form2.cpp
Qt Code:
  1. #include "form2.h"
  2. #include "ui_form2.h"
  3. #include "form1.h"
  4. #include "ui_form1.h"
  5.  
  6. Form2::Form2(QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::Form2)
  9. {
  10. ui->setupUi(this);
  11. }
  12.  
  13. Form2::~Form2()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void Form2::changeEvent(QEvent *e)
  19. {
  20. QWidget::changeEvent(e);
  21. switch (e->type()) {
  22. case QEvent::LanguageChange:
  23. ui->retranslateUi(this);
  24. break;
  25. default:
  26. break;
  27. }
  28. }
  29.  
  30. void Form2::load_form1()
  31. {
  32. form1 a;
  33. a.show();
  34. }
To copy to clipboard, switch view to plain text mode 

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

When I tried to new form1 like the below code

Form2 *f2 = new Form2(this) <- under button click on form 1
f2.show();

I got error
error: request for member ‘show’ in ‘a’, which is of non-class type ‘form1*’

if I remove the pointer I got this error
error: ‘QWidget::QWidget(const QWidget&)’ is private
within this context (points to class form1)

Can someone help me out? I also need to know how to pass the str string over to f2.

Thanks in advance.