Reputation: 81
I am using QCreator in Qt5. I have lineEdit_1 in MainWindow and lineEdit_2 in Dialog. When the user enters a value in lineEdit_1, that value should be automatically inserted in lineEdit_2. In order to do that, I have implemented the follows which is still giving me an error:
void Dialog::on_lineEdit_editingFinished()
{
MainWindow main;
ui->lineEdit->addItem(main->lineEdit->text());
}
Any help would be appreciated.
Upvotes: 0
Views: 861
Reputation: 49279
There are a number of things wrong with your code:
QLinedEdit
doesn't have an addItem(QString)
method. It has a setText(QString)
.
you create a MainWindow
on the stack, this surely isn't right. You need to reference your original main window, not create a new one. You can access the original widget pointer if you parent the dialog to it when you create it, and cast the parent pointer to MainWindow *
using qobejct_cast()
.
you use pointer syntax, but MainWindow main;
is not a pointer but an instance.
you are setting an event handler for when the content of the dialog line edit is changed, which is the opposite of what you say you want to do, since you say you want changes in the main ui line edit to be reflected by the dialog line edit.
Upvotes: 1