PDA

View Full Version : problem in Qt4 dialog



grsandeep85
27th August 2009, 07:09
Hi All,

I have created a dialog(Disp) in Qt-4.2 which has 3 lineEdits namely X,Y,Z when the user press a key from keyboard a new diaolg(DatumForm) will open which has 4 namely lineEdits Sl.No, Xdat, Ydat,Zdat and user will enter some values in the lineEdits when he press the Emter key from keyboard the values of Xdat, Ydat,Zdat sholud be displayed in X,Y,Z lineEdits....

I am not able to display values in Dispd dialog .. here is the code snippet


void Disp::openDatumForm()
{
DatumForm *datumform = new DatumForm(this);
datumform->show();
// datumform->setWFlags();
datumform->move(35, 90);
if( datumform->exec() == QDialog::Accepted)
{
DatumVal = Datumno_Val;
XVal = Xdatum_Val;
YVal = Ydatum_Val;
ZVal = Zdatum_Val;
datuminitial();
}
}

But the same thing is working in Qt-3.3 and also i have attached the ui forms

Please help us.:)

spirit
27th August 2009, 07:27
oftop: you don't need to call QDialog::show, because then you call QDialog::exec. btw, you don't free memory of you dialog. it would be better if you create that dialog in a stack, like this


void Disp:penDatumForm()
{
DatumForm datumform(this);
datumform.move(35, 90);
if(datumform.exec() == QDialog::Accepted) {
DatumVal = Datumno_Val;
XVal = Xdatum_Val;
YVal = Ydatum_Val;
ZVal = Zdatum_Val;
datuminitial();
}
}

ps. could you attach minimal compilable example which reproduces the problem?

grsandeep85
27th August 2009, 07:40
Thanks for the reply,

i tried with your code but i same problem till now i was using Qt-3.3 and i have done the applications using Qt-3.3 now i have migrated to Qt-4.2

I have attached the .cpp and .h file of the applications you can go through it and let me know where i am going wrong.

spirit
27th August 2009, 07:59
ok, the problem is in Disp:: openDatumForm in this line


...
if(datumform.exec() == QDialog::Accepted)
...

when you close this dialog by Alt+F4 then the result of exec will be QDialog::Rejected and you pass this block


{
DatumVal = Datumno_Val;
XVal = Xdatum_Val;
YVal = Ydatum_Val;
ZVal = Zdatum_Val;
datuminitial();
}

there is two ways:
add a "OK" button in that dialog and connect signal QPushButton::clicked with QDialog::accept and leave this code unchanged


void Disp::openDatumForm()
{
DatumForm datumform(this);
datumform.move(35, 90);
if(datumform.exec() == QDialog::Accepted) {
DatumVal = Datumno_Val;
XVal = Xdatum_Val;
YVal = Ydatum_Val;
ZVal = Zdatum_Val;
datuminitial();
}
}

the second ways is: to use code like this


void Disp::openDatumForm()
{
DatumForm datumform(this);
datumform.move(35, 90);
datumform.exec();
DatumVal = Datumno_Val;
XVal = Xdatum_Val;
YVal = Ydatum_Val;
ZVal = Zdatum_Val;
datuminitial();
}

in this case there is no need to add extra button in the dialog, but you also lose checking of the dialog acception or rejection.

grsandeep85
27th August 2009, 09:14
I tried with both the ways but i am not able to display the values in the Disp form same problem. During the start of the applications the lineEdits sholud display 0.000 and that is not happening here is start up code snippet..


Disp::Disp (QDialog *parent)
:QDialog(parent)
{

setupUi(this);

qDebug( "Init Function ( During StartUp)" );

xlineEdit->setText("0.000");

ylineEdit->setText("0.000");

zlineEdit->setText("0.000");

decimals_mm = 3;
decimals_inch = 4;
datuminitial();
}

Please see my code attached and help us.

spirit
27th August 2009, 09:18
I don't understand what you need...

grsandeep85
27th August 2009, 09:57
When i run my application all the lineEdits in Disp Form should display 0.000 this is done by

xlineEdit->setText("0.000");
ylineEdit->setText("0.000");
zlineEdit->setText("0.000");

but when i run the application it is displaying bank in all the lineEdits.