#include "form.h"
#include "ui_form.h"
#include<mainwindow.h>
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
MainWindow* m = new MainWindow;
connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(send()));
connect(this, SIGNAL(sendData(QString)) ,m, SLOT(textchanged(QString)) );
}
Form::~Form()
{
delete ui;
}
void Form::send(){
emit sendData(ui->lineEdit->text());
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<form.h>
#include<ui_form.h>.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Form* form = new Form;
connect(ui->pushButton , SIGNAL(clicked()) , this, SLOT(showadd()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::textchanged(QString data){
ui->lineEdit->setText(data);
}
void MainWindow::showadd(){
Form* form = new Form;
form->show();
}
#ifndef FORM_H
#define FORM_H
#include <QWidget>
namespace Ui {
class Form;
}
class Form : public QWidget
{
Q_OBJECT
public:
explicit Form(QWidget *parent = nullptr);
~Form();
public slots:
void send();
signals:
void sendData(QString data);
private:
Ui::Form *ui;
};
#endif // FORM_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void textchanged(QString data);
void showadd();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}