Hi,

I have a problem, i created a mainwindow UI that has pushbutton and label "text" like in this picture https://prnt.sc/soz9tm
and Rain ui that has pushbutton like in this picture https://prnt.sc/sozbaq

When i compile program, first it opens mainwindow ui and when i clik on pushbutton it opens rain ui.
I want when i click on rain ui's pushbutton to set mainwindow's label text to "It rains",
but i don't know how to access mainwindow's label with Rain's class.

here are my codes and what i tried

mainwindow.h

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include "rain.h"
  6.  
  7. QT_BEGIN_NAMESPACE
  8. namespace Ui { class MainWindow; }
  9. QT_END_NAMESPACE
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. MainWindow(QWidget *parent = nullptr);
  17. ~MainWindow();
  18.  
  19. private slots:
  20. void on_pushButton_clicked();
  21.  
  22. public:
  23. Ui::MainWindow *ui;
  24. };
  25. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 
mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent)
  5. : QMainWindow(parent)
  6. , ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. }
  10.  
  11. MainWindow::~MainWindow()
  12. {
  13. delete ui;
  14. }
  15.  
  16.  
  17. void MainWindow::on_pushButton_clicked()
  18. {
  19. this->hide();
  20. rain *test = new rain();
  21. test->show();
  22. }
To copy to clipboard, switch view to plain text mode 
rain.h
Qt Code:
  1. #ifndef RAIN_H
  2. #define RAIN_H
  3.  
  4. #include <QWidget>
  5. #include "mainwindow.h"
  6.  
  7. namespace Ui {
  8. class rain;
  9. }
  10.  
  11. class rain : public QWidget
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. explicit rain(QWidget *parent = nullptr);
  17. ~rain();
  18.  
  19. private slots:
  20. void on_pushButton_clicked();
  21.  
  22. private:
  23. Ui::rain *ui;
  24. };
  25.  
  26. #endif // RAIN_H
To copy to clipboard, switch view to plain text mode 
rain.cpp
Qt Code:
  1. #include "rain.h"
  2. #include "ui_rain.h"
  3. #include "mainwindow.h"
  4.  
  5. rain::rain(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::rain)
  8. {
  9. ui->setupUi(this);
  10.  
  11. }
  12.  
  13. rain::~rain()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void rain::on_pushButton_clicked()
  19. {
  20. this->hide();
  21. MainWindow *ma = new MainWindow(this);
  22.  
  23. ma->show();
  24. }
To copy to clipboard, switch view to plain text mode