You don't connect two line edits together there isn't any sense behind that.
You connect signals and slots from one window to another for example to change some GUI or execute functions etc...
You emit or catch a signal and perform some execution in a slot according to that caught signal.
example: dialog has a line edit , main window has a button and a line edit.
In main window constructor you set the text of the line edit to "hello"
ui->lineEdit->setText("hello");
ui->lineEdit->setText("hello");
To copy to clipboard, switch view to plain text mode
the on click slot of the button as follows :
void MainWindow::on_pushButton_clicked()
{
mDialog = new Dialog(this); // mDialog is declared in your header
connect(ui
->lineEdit,
SIGNAL(textChanged
(QString)),mDialog,
SLOT(setText
(QString)));
mDialog->setModal(true); // try it without this line too
mDialog->show();
ui
->lineEdit
->setText
("test"+QString::number(i
));
i++; // int i is declared in the header file
}
void MainWindow::on_pushButton_clicked()
{
mDialog = new Dialog(this); // mDialog is declared in your header
connect(ui->lineEdit,SIGNAL(textChanged(QString)),mDialog,SLOT(setText(QString)));
mDialog->setModal(true); // try it without this line too
mDialog->show();
ui->lineEdit->setText("test"+QString::number(i));
i++; // int i is declared in the header file
}
To copy to clipboard, switch view to plain text mode
in your dialog you have a line edit and setText slot
void Dialog
::setText(QString str
) // declared in you .hpp as a public slot {
ui->lineEdit->setText(str);
}
void Dialog::setText(QString str) // declared in you .hpp as a public slot
{
ui->lineEdit->setText(str);
}
To copy to clipboard, switch view to plain text mode
so here anytime you press the button in main window a dialog will appear having the same text on the mainWindo in the line edit.
Now change it into this,
in your dialog add a button
void Dialog::on_pushButton_clicked()
{
ui
->lineEdit
->setText
("later"+QString::number(i
));
i++; // declare it in your header
emit sendText(ui->lineEdit->text()); // declare this signal in your header under signals
}
void Dialog::on_pushButton_clicked()
{
ui->lineEdit->setText("later"+QString::number(i));
i++; // declare it in your header
emit sendText(ui->lineEdit->text()); // declare this signal in your header under signals
}
To copy to clipboard, switch view to plain text mode
and in your MainWindow add a slot
void MainWindow
::setMainWindowText(QString str
) {
ui->lineEdit->setText(str);
}
void MainWindow::setMainWindowText(QString str)
{
ui->lineEdit->setText(str);
}
To copy to clipboard, switch view to plain text mode
and of course add this under your old connect statement :
connect(mDialog,
SIGNAL(sendText
(QString)),
this,
SLOT(setMainWindowText
(QString)));
connect(mDialog,SIGNAL(sendText(QString)),this,SLOT(setMainWindowText(QString)));
To copy to clipboard, switch view to plain text mode
now when you press the button of mainwindow you will change the text in the dialog and when you press the button in the dialog you will change the text of the main window.
this should explain and clear it all.
good luck.
Bookmarks