Results 1 to 6 of 6

Thread: Pass variable from a form to another form

  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Pass variable from a form to another form

    How to pass a value in the textbox from a form to another textbox in another form..

    Thanks in advanced...

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Pass variable from a form to another form

    You can use the signal and slot 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.

  3. #3
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: Pass variable from a form to another form

    thanks i will try it.

  4. #4
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: Pass variable from a form to another form

    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

  5. #5
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Pass variable from a form to another form

    I had this same question a while back. Check it out here.
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

  6. #6
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Pass variable from a form to another form

    I am novice but my way is:

    principal.cpp
    Qt Code:
    1. void Principal::on_pushButton_facturacion_clicked()
    2. {
    3. Facturacion *form_factu = new Facturacion; //Create new form with other class
    4. form_factu->show();
    5.  
    6. 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
    7. }
    8.  
    9. void Principal::muestramenu(QString str_local)
    10. {
    11. qDebug() << "Back to main" << str_local;
    12. }
    To copy to clipboard, switch view to plain text mode 


    facturacion.h
    Qt Code:
    1. class Facturacion....
    2. {
    3. ....
    4. signals:
    5. void cambia(QString);
    6. }
    To copy to clipboard, switch view to plain text mode 


    facturacion.cpp
    Qt Code:
    1. void Facturacion::on_edit_onchange()
    2. {
    3. QString name;
    4. name = f_ui->edit->Text();
    5. emit cambia(name);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Sorry for errors and my bad english.
    Last edited by cygnus2k; 8th February 2011 at 18:24.

Similar Threads

  1. How can I access public variable parent Form
    By validator in forum Qt Programming
    Replies: 14
    Last Post: 18th December 2008, 21:12
  2. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  3. How to pass values in 1 form to another
    By maveric in forum Newbie
    Replies: 4
    Last Post: 5th June 2008, 07:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.