PDA

View Full Version : Pass variable from a form to another form



dark1988
7th July 2008, 09:36
How to pass a value in the textbox from a form to another textbox in another form..

Thanks in advanced...

munna
7th July 2008, 10:22
You can use the signal and slot (http://doc.trolltech.com/4.4/signalsandslots.html) mechanism for this. On the click of submit button in form1, emit a signal with the value in the textbox. Connect this signal to a slot in the form2 and get the value there.

dark1988
7th July 2008, 10:52
thanks:) i will try it.

dark1988
7th July 2008, 11:04
ParentWindow a,b;
QObject::connect(&a, SIGNAL(valueChange(QString)),
&b,SLOT(setValues(QString)));

textfield -> setText(b.getValues());

But the value didn't appear in the textfield...
May i noe wrong with my code..

Or give some sample for mi to reference..
thanks:)

fnmblot
7th July 2008, 18:27
I had this same question a while back. Check it out here (http://www.qtcentre.org/forum/f-newbie-4/t-transfering-data-from-a-dialog-to-the-mainwindow-7193.html).

cygnus2k
8th February 2011, 19:19
I am novice but my way is:

principal.cpp


void Principal::on_pushButton_facturacion_clicked()
{
Facturacion *form_factu = new Facturacion; //Create new form with other class
form_factu->show();

QObject::connect(form_factu, SIGNAL(cambia(str_remote)), this, SLOT(muestramenu(str_local))); //Connect when is emit signal cambia in the child form and pass the string to local function
}

void Principal::muestramenu(QString str_local)
{
qDebug() << "Back to main" << str_local;
}


facturacion.h

class Facturacion....
{
....
signals:
void cambia(QString);
}



facturacion.cpp


void Facturacion::on_edit_onchange()
{
QString name;
name = f_ui->edit->Text();
emit cambia(name);
}

Sorry for errors and my bad english. :)