PDA

View Full Version : pass variables between 2 forms



restiz
16th June 2006, 15:11
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?

sumsin
17th June 2006, 09:19
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).

restiz
17th June 2006, 12:50
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...

zlatko
17th June 2006, 14:34
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 ?

patrik08
17th June 2006, 16:30
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 .....



/* write a value */
QSettings setter;
mydir = fileName.left(fileName.lastIndexOf("/"))+"/";
setter.setValue("LastDir",mydir);
/* read a value .... */
QSettings setter;
QString fileName = QFileDialog::getSaveFileName(this, "Export PDF",QString(setter.value("LastDir").toString()), "*.pdf");


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


/* QLineEdit editable true */
for (int i=0;i<textList.size();i++){
obname =QString(textList[i]->objectName());
if (obname.startsWith("TABLENAME_")) { /* ID_CLIENTE*/
dbfieldname = obname.right(obname.size() - 8);
valutadata = textList[i]->text();
Box_att.insert(loopnext++,QStringList() << dbfieldname << valutadata);
/*qDebug() << "### dbfieldname" << dbfieldname << " pos " << loopnext; */
if (valutadata.size() < 1) {
vuoti++;
}
}
}
.....................
QStringList insertliner;
UpdateQuery::Iterator it;
for ( it = Box_att.begin(); it != Box_att.end(); ++it ) {
QStringList itemsetter = it.value();
QString sx = QString(itemsetter.at(0))+"='"+QString(itemsetter.at(1))+"'";
insertliner.append(sx);
}

QString update_ALL = insertliner.join(", ");
QString queryUpdate = QString( "UPDATE TABLENAME SET %1 WHERE ID=%2" ).arg( update_ALL , QString::number(idogg) );
/*qDebug() << "### queryUpdate " << queryUpdate; */





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....

jacek
17th June 2006, 16:42
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:
void Form1::passDataToSecondForm()
{
// _form2 points to an object that represents the second form.
_form2->setSomething( _ui.someLineEdit->text() );
}

patrik08
17th June 2006, 17:04
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 ....

jacek
17th June 2006, 17:13
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.