PDA

View Full Version : Does a QDoubleValidator *allows* the user to enter incorect values?



hickscorp
18th April 2007, 14:24
Hello to everyone,

I have a simple qdialog, which contains a QLineEdit (txtValue).
In my dialog's constructor, i do as follows:


QDoubleValidator* pValidator = new QDoubleValidator(0, 1000, 1, txtValue);
pValidator->setRange(0, 1000, 1);
txtValue->setValidator(pValidator);


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.

marcel
18th April 2007, 14:27
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.

hickscorp
18th April 2007, 14:29
Marcel,

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

Thanks :)
Pierre.

hickscorp
18th April 2007, 14:39
I just read the doc for fixUp and i understood how it works :)

Thanks AGAIN marcel XD

jpn
18th April 2007, 16:33
Another option would be to use a QRegExpValidator. Search the forums, there are examples of using with decimal numbers out there. ;)

wysota
18th April 2007, 17:57
"9999999" is perfectly valid for range 0-1000 as you may then enter "e-10" and have a number that is in valid range.

Caius Aérobus
29th September 2008, 11:34
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?

wysota
29th September 2008, 23:06
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.

ericwny
1st October 2008, 18:37
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.

wysota
1st October 2008, 19:06
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.

ericwny
1st October 2008, 19:18
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.

wysota
1st October 2008, 20:02
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 :)

ericwny
1st October 2008, 20:17
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.

wysota
1st October 2008, 20:31
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?

ericwny
1st October 2008, 20:42
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.

wysota
1st October 2008, 23:43
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).