Results 1 to 7 of 7

Thread: How do i create a boxchecker?

  1. #1
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How do i create a boxchecker?

    Hi
    i would like to know how i can check some lineedit's content on button click?
    i chose the clicked() Event of a button and now i want to create a function to check if something is in the dialog's lineedits or not.
    i want to have a separate function that i call if the event is triggered.
    how can i solve this?

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do i create a boxchecker?

    Hi terreox,
    I generally do that with a lineEdit and a Checkbox i put right next to it (like buddies -> http://www.youtube.com/watch?v=2edb0...ure=plpp_video). I disable the checkbox as checkable so that the user cannot check the info. The events I use are if return clicked or (I think this is going to be more useful to you) editing finished, this triggers when the focus on the lineEdit is lost. I ll give you an example:

    Qt Code:
    1. void Formulario::on_lineEdit_2_editingFinished()
    2. {
    3. int x = this->ui->lineEdit_2->text ().length ();
    4. if ( x< 50 && x> 3){
    5. this->ui->checkBox_2->setChecked (true);
    6. this->ui->checkBox_2->setIcon (QIcon ());
    7. }else{
    8. this->ui->checkBox_2->setIcon (QIcon (":ImagesMilk/Iconos/25.png"));
    9. this->ui->checkBox_2->setChecked (false);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    tell me if this helps you


    Added after 4 minutes:


    Here is an example of the form that goes with that code. So you start typing in a line edit you press Tab for example to move to the next linedit and the SLOT on editing finished triggers. You can also add an icon to the checkbox to show that something went wrong (for example the linedit doesnt contains what you want)

    ejemplo.JPG

    hope it brings you some light!
    Last edited by KillGabio; 1st February 2012 at 16:13.

  3. The following user says thank you to KillGabio for this useful post:

    Terreox (1st February 2012)

  4. #3
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do i create a boxchecker?

    ok thanks for you solution.
    it is a different way than i want but with yours i can show the user if something is wrong or not.
    what i want is a bit different:
    i put QRegEx on all boxes so that the user is limited while typing.
    at the end of my dialog there is a "Next" button. If the user presses this button the program shall check if e.g. all boxes are filled with content. if only one box is empty than the user shall be noticed about that.
    I tried the button_clicked() event and added an extra function in that event. this extra function shall check if every box is not empty anymore. but how can i tell the function what dialog he shall use? i need something that i can call e.g. lineedit->text() but how can i do that?

    Qt Code:
    1. bool fieldChecker();
    2.  
    3. void Something::on_pushButton_clicked()
    4. {
    5. if(fieldChecker() != true){
    6. QMessageBox::warning(this, "Error","lineedit is empty!");
    7. }else{
    8. QMessageBox::information(this, "Granted", "lineedit is not empty");
    9. }
    10. }
    11.  
    12. bool fieldChecker(){
    13. if(lineedit->text() == ""){
    14. return false;
    15. }
    16. return true;
    17. }
    To copy to clipboard, switch view to plain text mode 

    The problem is: I cannot call lineedit->text() in fieldChecker(). What do i have to do to be able to use that?

  5. #4
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do i create a boxchecker?

    the lineEdit is created by you or the Designer? if its created in Designed mode then you use it like this

    this->ui->lineedit

  6. #5
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do i create a boxchecker?

    yeah that is what i tried too but it does not work.
    if i try this in void Something:n_pushButton_clicked() it works.
    but if i try this in bool fieldChecker() it does not.

  7. #6
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do i create a boxchecker?

    mmmm try adding that function to the Something class...

    for example:

    Something.h
    .
    .
    .
    public:
    bool fieldChecker ();
    .
    .
    .
    Something.cpp

    bool Something::fieldChecker(){
    if(ui->lineedit->text() == ""){
    return false;
    }
    return true;
    }
    Still you havent told me if you create the linedit in Design or you create it :P

  8. #7
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do i create a boxchecker?

    oh yes i forgot it sry.
    i created the lineedit in the Designer.
    Told with a friend about this problem and found the same solution.
    Did not think about this way - the easy way The solution was too simple to think about it directly but i think it is normal as a newbie like me
    Anyway many thanks to you!

Similar Threads

  1. How to Create lib in Qt.
    By shyam prasad in forum Qt Programming
    Replies: 6
    Last Post: 14th August 2012, 10:02
  2. Qt in VS does not create an .exe
    By Nazgul in forum Installation and Deployment
    Replies: 7
    Last Post: 14th August 2012, 09:34
  3. How do I create a DLL for QT
    By zartoch in forum Newbie
    Replies: 2
    Last Post: 8th May 2009, 06:28
  4. Replies: 4
    Last Post: 1st May 2009, 11:00
  5. How to create a SDK?
    By blackfox in forum Qt Programming
    Replies: 0
    Last Post: 10th September 2008, 10:23

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.