PDA

View Full Version : Transfer the values entered in one line edit to another present in different window



Deathshadow
27th February 2018, 06:48
The mainwindow header looks like:


class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
bool eventFilter(QObject *obj, QEvent *event);
~MainWindow();

private:
Ui::MainWindow *ui;
connection *con;
};

Mainwindow source looks like:




MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

ui->lineEdit->installEventFilter(this);
QObjectList o_list = ui->lineEdit->children();
for(int i = 0; i < o_list.length(); i++)
{
QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[i]);
if(cast)
cast->installEventFilter(this);
}

}



bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseButtonPress)
{
con->show();
}
return false;
}


MainWindow::~MainWindow()
{
delete ui;
}

the Ui window contains a lineedit each.the connection window contains a textbox and the mainwindow contains another.The objective is to transfer the string/data from the widget window to main window using connect or any other method.

high_flyer
27th February 2018, 15:22
So, are you giving us assignments or what?

What is the problem you have, what help do you need?

Deathshadow
28th February 2018, 06:53
thank you for suggesting about S.O.L.I.D. I'm just a beginner and haven't used Qt much.I just want to know that if we want to transfer values written in lineedit present in a widget opened from mainwindow, to a lineedit present in mainwindow.

high_flyer
28th February 2018, 11:01
The S.O.L.I.D principles information is part of my signature, not the post :-)

The way you write, and your code suggests you don't really understand basic C++.
The answer to your question would be that the information of your UI should be held separately from the UI, thus available to any UI part in your application.

In your code, you have a member variable 'connection' which is not initialized (so it will probably crash in your eventFilter() and its not visible where you destroy it either.

Before you start working with a tool kit like Qt, better start with basic C++ on basic concepts of OOP.