Hello,
I want to send a message from a QLineEdit (lineEdit) after clicking a QPushButton (pushButton) from a window (test) and print it to a QLabel (label) in another window (test2).
This is what I've done so far:
test.h
Qt Code:
  1. #ifndef TEST_H
  2. #define TEST_H
  3.  
  4. #include <QMainWindow>
  5. #include "test2.h"
  6. namespace Ui {
  7. class test;
  8. }
  9.  
  10. class test : public QMainWindow
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit test(QWidget *parent = 0);
  16. ~test();
  17. signals:
  18. void notifyValueSent(const QString value);
  19. private slots:
  20. void on_pushButton_clicked();
  21.  
  22. private:
  23. Ui::test *ui;
  24. };
  25.  
  26. #endif // TEST_H
To copy to clipboard, switch view to plain text mode 
test.cpp
Qt Code:
  1. #include "test.h"
  2. #include "ui_test.h"
  3.  
  4. test::test(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::test)
  7. {
  8. ui->setupUi(this);
  9.  
  10. }
  11.  
  12. test::~test()
  13. {
  14. delete ui;
  15. }
  16.  
  17. void test::on_pushButton_clicked()
  18. {
  19. QString value = ui->lineEdit->text();
  20. emit notifyValueSent(value);
  21. }
To copy to clipboard, switch view to plain text mode 
test2.h
Qt Code:
  1. #ifndef TEST2_H
  2. #define TEST2_H
  3.  
  4. #include <QWidget>
  5. #include "test.h"
  6. namespace Ui {
  7. class test2;
  8. }
  9.  
  10. class test2 : public QWidget
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit test2(QWidget *parent = 0);
  16. ~test2();
  17. private slots:
  18. void onValueSent(const QString value);
  19. private:
  20. Ui::test2 *ui;
  21. };
  22.  
  23. #endif // TEST2_H
To copy to clipboard, switch view to plain text mode 
test2.cpp
Qt Code:
  1. #include "test2.h"
  2. #include "test.h"
  3. #include "ui_test2.h"
  4.  
  5. test2::test2(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::test2)
  8. {
  9. ui->setupUi(this);
  10. }
  11.  
  12. test2::~test2()
  13. {
  14. delete ui;
  15. }
  16. void test2::onValueSent(QString value){
  17.  
  18. ui->label->setText(value);
  19. }
To copy to clipboard, switch view to plain text mode 
main.cpp
Qt Code:
  1. #include "test.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. test t;
  8. test2 t2;
  9. QObject::connect(&t,SIGNAL(notifyValueSent(value)),&t2,SLOT(onValueSent(value)));
  10. t.show();
  11. return a.exec();
  12. }
To copy to clipboard, switch view to plain text mode 
Thank you.