Results 1 to 5 of 5

Thread: Checking that value of ui elements has been changed.

  1. #1
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Post Checking that value of ui elements has been changed.

    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,
    Qt Code:
    1. connect(ui->leAge,SIGNAL(textChanged(QString)),this,SLOT(functChanged())); //In Constructor
    2.  
    3. void DemoDialog::functChanged() //Will be called if value of line edit (ui->leAge) is changed
    4. {
    5. flag=true;
    6. }
    7.  
    8. void DemoDialog::closeEvent(QCloseEvent *event)
    9. {
    10. if (flag) {
    11. if (QMessageBox::warning(this,"Close","Do you want to close?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes) {
    12. this->close();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advnc.

    Regards,
    Rohit

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Checking that value of ui elements has been changed.

    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,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Checking that value of ui elements has been changed.

    Quote Originally Posted by anda_skoa View Post
    If you have a method that reads all input elements_
    No I don't have any. Can that be done?
    Quote Originally Posted by anda_skoa View Post
    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?
    Qt Code:
    1. connect(ui->leAge,SIGNAL(textChanged(QString)),this,SLOT(functChanged())); //In Constructor
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by rohitkk; 3rd April 2014 at 14:35.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Checking that value of ui elements has been changed.

    Quote Originally Posted by rohitkk View Post
    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?

    Quote Originally Posted by rohitkk View Post
    Wouldn't there will be an overhead of comparing each element?
    Sure, but likey negligible.

    Quote Originally Posted by rohitkk View Post
    Can this loc be changed?
    Qt Code:
    1. connect(ui->leAge,SIGNAL(textChanged(QString)),this,SLOT(functChanged())); //In Constructor
    To copy to clipboard, switch view to plain text mode 

    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,
    _

  5. #5
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Checking that value of ui elements has been changed.

    Quote Originally Posted by anda_skoa View Post
    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.
    Quote Originally Posted by anda_skoa View Post
    Sure, but likey negligible.
    How come , if the number of ui elements is huge.

Similar Threads

  1. Checking QByteArray for certain values
    By -Kyr0s- in forum Qt Programming
    Replies: 19
    Last Post: 14th November 2011, 11:47
  2. Checking QByteArray
    By camol in forum Qt Programming
    Replies: 3
    Last Post: 18th March 2011, 14:07
  3. Checking for gui events
    By mgb in forum Qt Programming
    Replies: 8
    Last Post: 8th February 2011, 23:07
  4. Checking if bad pointer?
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2007, 10:06
  5. checking for null
    By drkbkr in forum General Programming
    Replies: 6
    Last Post: 13th March 2006, 22:54

Tags for this Thread

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.