PDA

View Full Version : access on main window from anothe window (e.g Dialog)



Malek
30th July 2010, 22:05
Good evening everybody...

My Question as simple as in the title !!
I try to write in line edit witch is in the main window,while my button exist on another window (dialog window).

When I try to make that, I put in the event handler the dialog button:

MainWindow::ui->lineEdit_1->text() = :ui->lineEdit_2->text() ;
while :lineEdit_1 is in the main window and :lineEdit_2 is in the dialoge.

but the honorable compiler tell me that :
1) Object missing in reference to 'MainWindow::ui' .............in mainwindow.h
2)from this location .............in dialog.cpp

I have search about this, but I didn't understand the meant.Let alone most of what I found was about multi threading not about forms.

Thank you.

Zlatomir
30th July 2010, 23:50
Use signals and slots to update your lineEdit
LE: also you will need setText(QString); (or &) because the text() returns the QString, so you cant do assignment to lineedit.text().

Malek
4th August 2010, 19:10
Zlatomir .Sorry for the delay.

Thank you for your replay.
I think that your suggestion is more professional ,but I have found another simple solution by make function in class dialog.This functoin have to return the content of lineEdit.
e.g

QString dialog::getLineEditText() const
{
return ui->lineEdit->text();
}

Then call it like after execute the dialog


if (x.exec() == QDialog::Accepted)
ui->lineEdit->setText(x.getLineEditText());


THANK YOU FOR YOUR INTEREST.