Results 1 to 9 of 9

Thread: Behavior not expected by QDoubleValidator()

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Behavior not expected by QDoubleValidator()

    Hi people,

    I noticed recently that there is a problem with QDoubleValidator (), which didn't happen when I used the QT 4.6.x.
    Even defining the validation, for example, two decimal places the QLineEdit supports typing in more decimal places than it was defined.
    The QLineEdit was created without any special parameters set.

    leNUMBER-> setValidator (new QDoubleValidator (0.0,999999999.99,2, leNUMBER));
    I can enter the field, for example, 123.4567895555555.

    The funny thing is, as I said, the behavior prior to version 4.7.x
    wasn't to allow more informed than the decimal places, which is correct.

    If anyone has any suggestion for me I would be very grateful.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Behavior not expected by QDoubleValidator()

    That is because the scientific notation, use something like this:
    Qt Code:
    1. QLineEdit *le = new QLineEdit;
    2. QDoubleValidator *validator = new QDoubleValidator (0.0, 99.99, 2, le);
    3. validator->setNotation(QDoubleValidator::StandardNotation);
    4. le->setValidator(validator);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Behavior not expected by QDoubleValidator()

    Zlatomir Hi,

    I followed your example and it works, but there is a strange behavior that
    I would like (if you can) explain.

    If I set the maximum value 99.99 as I type up to 99. and not allowed to enter after the decimal point.
    If I set the maximum value to 999.99 I can only enter values this way: 999. or 89.9 or .99.
    That is, before the decimal point three digits can not exist for the value after the point decimail.
    If the value in less than three digits to get the point and only one digit after.
    If I place a value less than 1 (eg .50) QLineEdit does not allow me to put anything on the field.

    In short, I can not type for example: 999.99 486.88 15.66 1:55 1:00 properly, as happened before.

    With higher values the deal gets even crazier still:
    If I define as the maximum 999999999.99 see what happens:

    Case 1: Only allow enter up to 999999999. (does not allow decimal places)
    Case 2: If I enter values less than the maximum allowed it lets you enter more than the number of homes decimail defined: Ex: 156.6666666

    Super weird!

    Thanks in advance.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Behavior not expected by QDoubleValidator()

    This behavior i can't replicate, i wrote this simple example:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv){
    4. QApplication a(argc, argv);
    5. QLineEdit *le = new QLineEdit(0);
    6.  
    7. QDoubleValidator *validator = new QDoubleValidator (0.0, 999999999.99, 2, le);
    8. validator->setNotation(QDoubleValidator::StandardNotation);
    9. le->setValidator(validator);
    10. le->show();
    11. int ret = a.exec();
    12. delete le;
    13. return ret;
    14. }
    To copy to clipboard, switch view to plain text mode 
    And it works on my machine with both 99.99 and 999999999.99
    LE: i use Qt SDK tech preview on Windows.

  5. #5
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Behavior not expected by QDoubleValidator()

    Thanks for while,

    I use Qt SDK 2010.05 on windows and native fedora 14 (32bits) qt 4.7.1
    in both the problem happens.

    Exists a information of bug in qt bug tracker about this: see [QTBUG-14852]
    Last edited by vcp; 2nd February 2011 at 13:08.

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Behavior not expected by QDoubleValidator()

    It doesn't look like the same bug to me.
    Maybe the one you have it was fixed in the newer builds (because on my machine as i said i have the Tech Preview)
    I'll try with Qt SDK 2010.05 on kubuntu, but later this evening.

  7. #7
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Behavior not expected by QDoubleValidator()

    Ok, I'm waiting for your test.
    I tried various approaches so far, but nothing
    doing the same effect as before.
    This is a big problem.

  8. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Behavior not expected by QDoubleValidator()

    I can't replicate your problem, tried the example i posted earlier with: Qt SDK 2010.05 on Kubuntu and Qt 4.7.0 integrated in VS 2008 (Win 7).

  9. #9
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Behavior not expected by QDoubleValidator()

    Hi,

    Well. That's it!

    I installed the SDK 2010.03 Qt (Qt 4.6.3) and QDoubleValidator had expected behavior.
    That is, regarding the number of decimals and format type.
    If I enter a range from 0.0 to 999999999.99 eg,
    typing occurs as expected. Allowing values enter the range and informed typing correct format.

    Well, now is the problem and the question: What to do?
    Attached Files Attached Files
    Last edited by vcp; 3rd February 2011 at 11:23.

Similar Threads

  1. QDoubleValidator, top and button range does not work..
    By webquinty in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 26th August 2009, 09:17
  2. QDoubleValidator
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 5th February 2009, 19:44
  3. QDoubleSpinBox and QDoubleValidator
    By George Neil in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2008, 00:36
  4. QDoubleValidator and setDecimals
    By zorro68 in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2007, 18:18
  5. QDoubleValidator
    By cristiano in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2007, 21:10

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
  •  
Qt is a trademark of The Qt Company.