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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "rain.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
{
Q_OBJECT
public:
MainWindow
(QWidget *parent
= nullptr
);
~MainWindow();
private slots:
void on_pushButton_clicked();
public:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "rain.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_pushButton_clicked();
public:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) , ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
this->hide();
rain *test = new rain();
test->show();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
this->hide();
rain *test = new rain();
test->show();
}
To copy to clipboard, switch view to plain text mode
rain.h
#ifndef RAIN_H
#define RAIN_H
#include <QWidget>
#include "mainwindow.h"
namespace Ui {
class rain;
}
{
Q_OBJECT
public:
explicit rain
(QWidget *parent
= nullptr
);
~rain();
private slots:
void on_pushButton_clicked();
private:
Ui::rain *ui;
};
#endif // RAIN_H
#ifndef RAIN_H
#define RAIN_H
#include <QWidget>
#include "mainwindow.h"
namespace Ui {
class rain;
}
class rain : public QWidget
{
Q_OBJECT
public:
explicit rain(QWidget *parent = nullptr);
~rain();
private slots:
void on_pushButton_clicked();
private:
Ui::rain *ui;
};
#endif // RAIN_H
To copy to clipboard, switch view to plain text mode
rain.cpp
#include "rain.h"
#include "ui_rain.h"
#include "mainwindow.h"
ui(new Ui::rain)
{
ui->setupUi(this);
}
rain::~rain()
{
delete ui;
}
void rain::on_pushButton_clicked()
{
this->hide();
MainWindow *ma = new MainWindow(this);
ma->show();
}
#include "rain.h"
#include "ui_rain.h"
#include "mainwindow.h"
rain::rain(QWidget *parent) :
QWidget(parent),
ui(new Ui::rain)
{
ui->setupUi(this);
}
rain::~rain()
{
delete ui;
}
void rain::on_pushButton_clicked()
{
this->hide();
MainWindow *ma = new MainWindow(this);
ma->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks