I need to change the value of a lineEdit text from other form.
I now that is a stupid question, I have searched through the forum but didn't found how to.
I have made a very simple project for illustrate: main class, form1 and form2 that contains a lineEdit and a pushButton each.
-The main function instantiate and show form1.
-In form1, the pushButton instantiate and show form2
-In form2, the pushButton should take the form2.lineEdit text (m_ui->lineEdit->text() ) and save it into form1.lineEdit

I don't know how to acces form1.lineEdit from form2.
If I try form1->lineEdit->text() it throw "form1 is not declarated at this scope"

I include the code.

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 form1; //Instanciate and show form1
  8. form1.show();
  9. return a.exec();
  10. }
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.  
  6. Form1::Form1(QWidget *parent)
  7. : QMainWindow(parent), ui(new Ui::Form1)
  8. {
  9. ui->setupUi(this);
  10. }
  11.  
  12. Form1::~Form1()
  13. {
  14. delete ui;
  15. }
  16.  
  17. void Form1::on_pushButton_clicked() //Instanciate and show form2
  18. {
  19. static Form2* form2 = new Form2(this);
  20. form2->show();
  21.  
  22. }
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. QMainWindow(parent),
  8. m_ui(new Ui::Form2)
  9. {
  10. m_ui->setupUi(this);
  11. }
  12.  
  13. Form2::~Form2()
  14. {
  15. delete m_ui;
  16. }
  17.  
  18. void Form2::changeEvent(QEvent *e)
  19. {
  20. QMainWindow::changeEvent(e);
  21. switch (e->type()) {
  22. case QEvent::LanguageChange:
  23. m_ui->retranslateUi(this);
  24. break;
  25. default:
  26. break;
  27. }
  28. }
  29.  
  30. void Form2::on_pushButton_clicked()
  31. {
  32. QString text=m_ui->lineEdit->text();
  33. //
  34. // Here I want to change the value of lineEdit widget in form1
  35. //
  36. // I think that "form1->ui->lineEdit->setText("xyz");" should work, but when building it throws:
  37. // "/home/ioseba/QT/Programas QT/2ventanas/form2.cpp:35: error: ‘form1’ was not declared in this scope
  38. }
To copy to clipboard, switch view to plain text mode 


Thanks for your time.