Results 1 to 16 of 16

Thread: Does a QDoubleValidator *allows* the user to enter incorect values?

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Does a QDoubleValidator *allows* the user to enter incorect values?

    Hello to everyone,

    I have a simple qdialog, which contains a QLineEdit (txtValue).
    In my dialog's constructor, i do as follows:
    Qt Code:
    1. QDoubleValidator* pValidator = new QDoubleValidator(0, 1000, 1, txtValue);
    2. pValidator->setRange(0, 1000, 1);
    3. txtValue->setValidator(pValidator);
    To copy to clipboard, switch view to plain text mode 

    My problem is, i'm still able to enter values like "9999999", also if a "setText" is done from "outside" (Like this txtValue->setText(QString::number(dNewValue)), there are too many decimal displayed (I want only 1 number after comma).

    What am i doing wrong here?
    Thank you,
    Pierre.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    You must reimplement the QValidator::fixup() function in a custom QDoubleValidator in order to modify the user input, and adjust it to fit in the upper/lower bounds.

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

    hickscorp (18th April 2007)

  4. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Marcel,

    Thanks, what about the decimal count problem? Will i fix it with the same reimplementation?

    Thanks
    Pierre.

  5. #4
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    I just read the doc for fixUp and i understood how it works

    Thanks AGAIN marcel XD

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Another option would be to use a QRegExpValidator. Search the forums, there are examples of using with decimal numbers out there.
    J-P Nurmi

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    "9999999" is perfectly valid for range 0-1000 as you may then enter "e-10" and have a number that is in valid range.

  8. #7
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Quote Originally Posted by marcel View Post
    You must reimplement the QValidator::fixup() function in a custom QDoubleValidator in order to modify the user input, and adjust it to fit in the upper/lower bounds.
    so what is the purpose of QDoubleValidator???? does it mean it is just a generic class for implementing validators, which cannot be used as a standalone class?

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    No, why? It's just after writing "99999" you can always write "e-99" and be inside 0.0-1.0 bounds If you don't like the scientific notation to be acceptable, you have to reimplement fixup or use a reg exp validator.

  10. #9
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    That's a pretty parsimonious response. And a very poor user interface. I'd be willing to bet the number users to whom it would even occur to use that format of input is downright microscopic.

    In any case you can still validate after losing focus or getting the enter/return key. But it doesn't. For me it makes this class downright useless. There's virtually no value to me if I have to implement the salient functionality myself.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Quote Originally Posted by ericwny View Post
    That's a pretty parsimonious response. And a very poor user interface. I'd be willing to bet the number users to whom it would even occur to use that format of input is downright microscopic.
    It's still a valid double value. You can override this behaviour by using QDoubleValidator::notation property.

    In any case you can still validate after losing focus or getting the enter/return key. But it doesn't. For me it makes this class downright useless. There's virtually no value to me if I have to implement the salient functionality myself.
    It validates, it doesn't fix. It's clearly said in the docs, by the way...

    For simple usecases it is really advised to use a regexp validator or better yet a spinbox.

  12. #11
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    I'm using 4.0.1. It does not say what you indicate in the docs I have. Also the this version does not have that property.

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    4.0.1 is like... over 3 years old. You can't blame something to behave incorrect if that behaviour was fixed only that you're still using an outdated version. Consider upgrading to 4.4.3

  14. #13
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    I'm glad you suggested that. I work on a commercial product so we need the commercial license. It happens we looked into upgrading some months ago but, trolltech wanted us to pay for support for the intervening years we didn't upgrade.

    That's the slimiest sales tactic I have ever heard of.


    ...and I have worked at Microsoft.

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Quote Originally Posted by ericwny View Post
    I'm glad you suggested that. I work on a commercial product so we need the commercial license. It happens we looked into upgrading some months ago but, trolltech wanted us to pay for support for the intervening years we didn't upgrade.
    You can buy a new licence instead of renewing it. TT wants you to pay not for the support but for prolonging the licence during the period you have been using it without paying. It's a weird strategy, I agree, but they seem very strict (and coherent) about it. The normal rule is you have 6 months to renew the licence after it expires.

    Look at it this way - if you rent a house and live in it, and suddenly stop paying but not stop living and then the owner comes and asks you to pay for the period of time you haven't been paying, you wouldn't be surprised, would you?

  16. #15
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Every other product offers an upgrade license - with the only requirement being you actually own an older version. I don't have to show that I have upgraded to every version along the way. I hope you can see the rental house analogy is extremely labored and little more than rationalization. Software isn't rented.

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does a QDoubleValidator *allows* the user to enter incorect values?

    Quote Originally Posted by ericwny View Post
    Software isn't rented.
    Actually it is. You don't necessarily buy software, you licence it. The same goes with publishing books, playing music in public, etc.

    Besides, it's the licencing scheme choice of Trolltech - by buying the licence you agreed to it. I don't like the scheme as well, but I have to live with it - they give you something on their terms. If you don't like those terms then don't accept them and don't use the product. But let's face it - the licence (and renewal) is really cheap considering what you get in return and how much can you earn with it.

    Every other product offers an upgrade license - with the only requirement being you actually own an older version.
    Oh... and that's not true as well... very often you stumble upon a limitation that you can only upgrade a product if you have one of X earlier versions (and not any earlier version) and sometimes even in a required configuration (i.e. consider a downgrade from Vista to XP).

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.