Results 1 to 7 of 7

Thread: How to prevent to insert in db only the mask if lineedit no filled

  1. #1
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to prevent to insert in db only the mask if lineedit no filled

    hello buddies,
    I have 2 lineedits with mask, one with phone mask an another with birthday mask.
    these two fields aren't required fields, so how can i prevent to insert in db only the mask when the user do not fill these fields?

    I tryed this before my insertRecord, but do not work:

    Qt Code:
    1. if (ui->leBirth->text() == " / / ")
    2. {
    3. ui->leBirth->clearMask();
    4. ui->leBirth->clear();
    5. }
    6.  
    7. if (ui->lePhone->text() == "( ) - ")
    8. {
    9. ui->lePhone->clearMask();
    10. ui->lePhone->clear();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot.
    Juliano

  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: How to prevent to insert in db only the mask if lineedit no filled

    Not sure why you posted code that you use to clear the widgets.

    How do you process the values before insertion into the database?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to prevent to insert in db only the mask if lineedit no filled

    An empty line edit with a mask returns the mask with optional characters removed.
    Qt Code:
    1. l.setInputMask("00/00/0000;_");
    2. // Displays "__/__/____" in the edit edit box
    3. qDebug() << l.text();
    4. // Output "//" not "00/00/0000"
    5.  
    6. l.setInputMask("(000) 000-0000;_");
    7. // Displays "(___) ___-____" in the edit edit box
    8. qDebug() << l.text();
    9. // Output "() -" not "(000) 000-0000"
    To copy to clipboard, switch view to plain text mode 
    Neither mask guarantees a valid value even if one is provided.

    BTW: QWidget::clearMask() has nothing to do with the line edit's input mask.

  4. #4
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to prevent to insert in db only the mask if lineedit no filled

    Ok, solved.

    anda_skoa
    , The ui->object->clear() was an desperate act (kkk) when the clearmask not worked, sorry, my bad.

    In my original code, i was setted the input mask in the form, in this format: phone: (xx)xxxx-xxxx, date: xx/xx/xxxx (and the clearMask() do not worked on code)

    so i had to change my approach. I set up the mask in my form initialization as the ChrisW67 sugestion:
    Qt Code:
    1. ui->leTelefone->setInputMask("(00)0000-0000;_");
    2. ui->leAniversaio->setInputMask("00/00/0000;_");
    To copy to clipboard, switch view to plain text mode 
    And before insert or update the data in database, i made this verification:
    Qt Code:
    1. if (ui->leTelefone->text() == "()-")
    2. ui->leTelefone->setInputMask(""); // prevent to insert only the mask in database
    3.  
    4. if (ui->leAniversaio->text() == "//")
    5. ui->leAniversaio->setInputMask("");
    To copy to clipboard, switch view to plain text mode 
    I don't know if this is the correct approach, but it worked!
    thanks a lot!
    Juliano

  5. #5
    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: How to prevent to insert in db only the mask if lineedit no filled

    I wonder why you change the mask instead of just not taking the value for insert?

    Cheers,
    _

  6. #6
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to prevent to insert in db only the mask if lineedit no filled

    because my mask was not setted on qlineedit keypress event (is this a good idea?). My masks was setted in project time, in the qlineedit property, in the form.

    In this form, i have 3 fields, name, phone, birthday. Only the name field is required, so if the user fill only the name field, the qlineedit masks are saved in database. maybe my inputMask format was wrong? (in that format xx/xx/xxxx and (xx)xxxx-xxxx)

    I have developing in others languages for some years, but my experience with C++ an Qt is only beginning, and i hope to begin in right way, so i apologies for my mistakes and thank for your comprehension.

    Juliano

  7. #7
    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: How to prevent to insert in db only the mask if lineedit no filled

    Quote Originally Posted by juliano.gomes View Post
    My masks was setted in project time, in the qlineedit property, in the form.
    Make sense, it probably doesn't need to change during runtime.

    I am asking why you are clearing the input mask as it as nothing to do with the question you have been asking.

    ChrisW67 showed you how to detect empty fields despite the mask, but instead of using that to detect when not to use the value you change the mask?

    Cheers,
    _

Similar Threads

  1. Replies: 19
    Last Post: 12th February 2014, 07:32
  2. Chech if filled
    By Kamran Kawish in forum Newbie
    Replies: 6
    Last Post: 17th October 2012, 11:30
  3. Performance with many filled polygons on screen
    By lni in forum Qt Programming
    Replies: 10
    Last Post: 14th September 2009, 10:53
  4. How to get QGraphicsRectItem filled color
    By wisconxing in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2009, 02:28
  5. How to get QGraphicsItem's filled color
    By wisconxing in forum Newbie
    Replies: 1
    Last Post: 2nd February 2009, 14:48

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.