Есть два окна. В одном окне LineEdit, в другом - PushButton. Как при нажатии кнопки передать ее надпись в LineEdit? Думал это все дело реализовать через указатель, но не вышло...
Класс первого окна (с LineEdit)
#ifndef WINDOW_H
#define WINDOW_H
#include <QDialog>
#include <QLineEdit>
#include "table.h"
class Table;
class Window : public QDialog
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
~Window();
Table *table;
QLineEdit *edit;
};
#endif // WINDOW_H
Его методы:
#include "window.h"
Window::Window(QWidget *parent): QDialog(parent)
{
table = new Table;
table->show();
edit = new QLineEdit(this);
}
Window::~Window()
{
}
Класс второго окна (с кнопкой):
#ifndef TABLE_H
#define TABLE_H
#include <QDialog>
#include <QPushButton>
#include "window.h"
class Window;
class Table : public QDialog
{
Q_OBJECT
public:
Table(QWidget *parent = 0);
~Table();
QPushButton *btn;
Window *ptr;
private slots:
void Slot();
};
#endif // TABLE_H
Его методы:
#include "table.h"
Table::Table(QWidget *parent) : QDialog(parent)
{
btn = new QPushButton(this);
btn->setText("Ok");
connect(btn, SIGNAL(clicked(bool)), this, SLOT(Slot()));
}
Table::~Table()
{
}
void Table::Slot()
{
ptr->edit->setText(btn->text());
}