Results 1 to 8 of 8

Thread: pass variables between 2 forms

  1. #1
    Join Date
    Jun 2006
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default pass variables between 2 forms

    Hello, i'm new in this community, my ask is the next

    I'm have two forms, in one the users introduce a date with the class QDateEdit then, the user's click on a push button and he goes to a second form, when the user do click in the first from, the date store pass to second form how to qstring, i'm know transform the control qdate to qstring, but, i don't know how pass the variable that contain the date (qstring) to the second form, how i did this?

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: pass variables between 2 forms

    You should use signal and slot mechenism.

    Connect the button's clicked() signal with your own slot say slotButtonClicked().
    And in the implementation of the slot you can create the object of second form and pass the date in its constructor( or set date by other set method).

  3. #3
    Join Date
    Jun 2006
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: pass variables between 2 forms

    Hello, well, what is you refer?, i'm implement in the firs form the signal (clicked) and a continuation, where implement the slot? in the first form or in the second?, sorry, i'm don't understand very well...

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: pass variables between 2 forms

    This question is related to c++ not Qt
    You catch click on button in your first class of course, and in your slot that called after button click pass date in form2 constructor..
    have you understand this mechanism ?
    a life without programming is like an empty bottle

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: pass variables between 2 forms

    Quote Originally Posted by restiz
    Hello, i'm new in this community, my ask is the next

    I'm have two forms, in one the users introduce a date with the class QDateEdit then, the user's click on a push button and he goes to a second form, when the user do click in the first from, the date store pass to second form how to qstring, i'm know transform the control qdate to qstring, but, i don't know how pass the variable that contain the date (qstring) to the second form, how i did this?
    You can use http://doc.trolltech.com/4.1/qsettings.html is easy ....
    is same as php session .....

    Qt Code:
    1. /* write a value */
    2. QSettings setter;
    3. mydir = fileName.left(fileName.lastIndexOf("/"))+"/";
    4. setter.setValue("LastDir",mydir);
    5. /* read a value .... */
    6. QSettings setter;
    7. QString fileName = QFileDialog::getSaveFileName(this, "Export PDF",QString(setter.value("LastDir").toString()), "*.pdf");
    To copy to clipboard, switch view to plain text mode 

    You save int or string ecc...

    int margin = settings.value("editor/wrapMargin").toInt();

    Or moore difficult.... save all objekt to a list....
    QList<QLineEdit *> textList = this->findChildren<QLineEdit *>();
    and read
    Qt Code:
    1. /* QLineEdit editable true */
    2. for (int i=0;i<textList.size();i++){
    3. obname =QString(textList[i]->objectName());
    4. if (obname.startsWith("TABLENAME_")) { /* ID_CLIENTE*/
    5. dbfieldname = obname.right(obname.size() - 8);
    6. valutadata = textList[i]->text();
    7. Box_att.insert(loopnext++,QStringList() << dbfieldname << valutadata);
    8. /*qDebug() << "### dbfieldname" << dbfieldname << " pos " << loopnext; */
    9. if (valutadata.size() < 1) {
    10. vuoti++;
    11. }
    12. }
    13. }
    14. .....................
    15. QStringList insertliner;
    16. UpdateQuery::Iterator it;
    17. for ( it = Box_att.begin(); it != Box_att.end(); ++it ) {
    18. QStringList itemsetter = it.value();
    19. QString sx = QString(itemsetter.at(0))+"='"+QString(itemsetter.at(1))+"'";
    20. insertliner.append(sx);
    21. }
    22.  
    23. QString update_ALL = insertliner.join(", ");
    24. QString queryUpdate = QString( "UPDATE TABLENAME SET %1 WHERE ID=%2" ).arg( update_ALL , QString::number(idogg) );
    25. /*qDebug() << "### queryUpdate " << queryUpdate; */
    To copy to clipboard, switch view to plain text mode 

    I update so sqltable and must no write fieldname or sql ... only pair objektname = (is filedname) and data grab from objekt...
    Fileld name only write a objekt name (tablename_fieldname) on ui designer file....

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pass variables between 2 forms

    Quote Originally Posted by patrik08
    You can use http://doc.trolltech.com/4.1/qsettings.html is easy ....
    is same as php session ..... .
    You don't use QSettings to pass data between forms. QSettings is for accessing application's configuration and other data that need permanent store.

    To pass data between forms you can use signals & slots mechanism or just create a normal methods that pass data:
    Qt Code:
    1. void Form1::passDataToSecondForm()
    2. {
    3. // _form2 points to an object that represents the second form.
    4. _form2->setSomething( _ui.someLineEdit->text() );
    5. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: pass variables between 2 forms

    Quote Originally Posted by jacek
    You don't use QSettings to pass data between forms. QSettings is for accessing application's configuration and other data that need permanent store.
    Normal i make form 1 ,2 ,3 ecc on a QTabWidget /QToolBox to access all on the same class.... und emit / slots from subclass to invoke parent the read action... and setting i put to a xml file... to make portable .... i not find the place / archives from qt to store data from QSettings .... on mac i not found .xxx hidden file from qsetting ... to delete or remove ....

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pass variables between 2 forms

    Quote Originally Posted by patrik08
    and setting i put to a xml file... to make portable ....
    If you want to make your settings portable between different OSes, you can use .ini files (QSettings::IniFormat) or even register you own format with QSettings::registerFormat(), but this has nothing to do with passing data between objects inside your application.

  9. The following user says thank you to jacek for this useful post:

    patrik08 (17th June 2006)

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.