PDA

View Full Version : Checking that value of ui elements has been changed.



rohitkk
3rd April 2014, 13:03
Hi All,

Is there any way to check that the ui elements(line edit,combo box,etc.) of the dialog has been changed.
What I want is to show a message to the user if he changes the value of any single ui element, saying that details have been partially filled.
What i can do is use connect for each ui element & based on the value changed of each element i am setting a boolean flag & at the time of close event i am checking that boolean flag.
But Its quite complicate to check it for each widget.
Is there any easier way.
Code that I am using for single ui element is,


connect(ui->leAge,SIGNAL(textChanged(QString)),this,SLOT(funct Changed())); //In Constructor

void DemoDialog::functChanged() //Will be called if value of line edit (ui->leAge) is changed
{
flag=true;
}

void DemoDialog::closeEvent(QCloseEvent *event)
{
if (flag) {
if (QMessageBox::warning(this,"Close","Do you want to close?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Y es) {
this->close();
}
}



Thanks in advnc.

Regards,
Rohit

anda_skoa
3rd April 2014, 13:42
Hmm. If you have a method that reads all input elements, then you could call that at the beginning, store all value locally, and then compare with the data at the end.

Cheers,
_

rohitkk
3rd April 2014, 14:35
If you have a method that reads all input elements_
No I don't have any. Can that be done?

store all value locally, and then compare with the data at the end. _
Wouldn't there will be an overhead of comparing each element?

Added after 40 minutes:

Can this loc be changed?



connect(ui->leAge,SIGNAL(textChanged(QString)),this,SLOT(funct Changed())); //In Constructor



Like instead of line edit as sender & text changed as signal, there could be dialog as sender & valueChanged be as signal or something like that?
Please suggest & reply.
Thanks in advance.

anda_skoa
3rd April 2014, 15:58
No I don't have any. Can that be done?

How do you then handle the user input if you don't read it from the UI elements?


Wouldn't there will be an overhead of comparing each element?

Sure, but likey negligible.


Can this loc be changed?



connect(ui->leAge,SIGNAL(textChanged(QString)),this,SLOT(funct Changed())); //In Constructor



Like instead of line edit as sender & text changed as signal, there could be dialog as sender & valueChanged be as signal or something like that?

If your dialog has such a signal, sure.

Cheers,
_

rohitkk
3rd April 2014, 16:45
How do you then handle the user input if you don't read it from the UI elements?

As i have said it is done by connecting the text changed event of line edit with the slot where a flag is set.


Sure, but likey negligible.

How come , if the number of ui elements is huge.