We have 2 ui forms. let's say form1.ui and form2.ui with their Header and Source files. In each form, there are a pushButton, a label and a variable QString. I want to show form2.ui by clicking the pushButton in form1.ui and show the form1.ui by clicking the pushButton in form2.ui.
and the text of the label1 be value of QString2 and the text of the label2 be value of QString1.
this is the outline: Project outline
form1.cpp:
#include "form1.h"
#include "ui_form1.h"
Form1::Form1(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
}
Form1::~Form1()
{
delete ui;
}
form1.h
#ifndef FORM1_H
#define FORM1_H
#include <QMainWindow>
namespace Ui {
class Form1;
}
class Form1 : public QMainWindow
{
Q_OBJECT
public:
explicit Form1(QWidget *parent = nullptr);
~Form1();
QString str1 = "some text 1";
private:
Ui::Form1 *ui;
};
#endif // FORM1_H
form2.cpp and form2.h are the same as these.
Can someone please share the code of each file that how this can work. thanks in advance.