HBQValidator

165 views
Skip to first unread message
Assigned to luigfe...@gmail.com by me

Luigi Ferraris

unread,
Dec 7, 2012, 8:03:57 AM12/7/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi Pritpal,
I follow your suggestion to open a thread related with my doubt or misunderstanding, related with:
https://groups.google.com/forum/?hl=it&fromgroups=#!searchin/qtcontribs/HBQValidator/qtcontribs/F9_5AwdjJMg/_jPASsmtzL0J

I need clarification about syntax because (probably) there is wrong code.

As I read here
https://groups.google.com/forum/?hl=it&fromgroups=#!searchin/qtcontribs/HBQValidator/qtcontribs/iK0Hi4yn6fI/UuQU31zBEvQJ

RETURN VALUE OF VALIDATION BLOCK:
                It is important to understand the rationale of return
                value of code-block supplied as only parameter to
                HBQValidator which controls the behavior of validation.
                This can be one of the following:

                1. NIL     : will be treated as input is valid.
                2. .T.     : will be treated as input is valid.
                3. .F.     : will not allow the current character.
                4. String  : will replace the input string with returned string.
                5. Numeric : will relocate the editing cursor to this position.
                6. Array   : { cModifiedText|NIL, nCursorPos|NIL, lValid|NIL }
                             the elements corresponds to above #4, #5, #1;2;3

USAGE example oEdit:setValidator( HBQValidator( {|cText, nPos| DoValidation( cText, nPos ) } ) )

But (within validator.prg) I see (and used/copied) this syntax:
HBQValidator( {|cText,nPos| ::getDate( cText, @nPos ) } ) )
and I told to me: I can use @ to alter parameter!

But probably is an error and code must be written as
HBQValidator( {|cText,nPos| ::getDate( cText, nPos ) } ) )

and relocation is performed via RETURN { cText, nPos, lRet }

Can you confirm?

Luigi Ferraris

Luigi Ferraris

unread,
Dec 7, 2012, 4:02:18 PM12/7/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
I have another question: how can be "removed" an installed validator with HbQt?
On QT I read : If v == 0, setValidator() removes the current input validator. The initial setting is to have no input validator.

I try: setValidator( 0 ), setValidator( HBQValidator( NIL ) )  but I receive QLINEEDIT:SETVALIDATOR(0) argument error.

Cheers

Luigi Ferraris

Dušan D. Majkić

unread,
Dec 7, 2012, 4:23:44 PM12/7/12
to qtcon...@googlegroups.com
> On QT I read : If v == 0, setValidator() removes the current input
> validator.

v is pointer in docs, so setValidator(NIL) should work.

If it doesn't work, then something like this should work:

setValidator( HBQVAlidator( {|| .T.} ) )

Regards,
Dusan Majkic
Wings Software

Luigi Ferraris

unread,
Dec 7, 2012, 4:33:05 PM12/7/12
to qtcon...@googlegroups.com
Il 07/12/2012 22.23, Dušan D. Majkić ha scritto:
> v is pointer in docs, so setValidator(NIL) should work.
>
> If it doesn't work, then something like this should work:
>
> setValidator( HBQVAlidator( {|| .T.} ) )
>
Hi Dušan, many thanks for your quickly answer! setValidator(NIL) works
fine .... as QT writes: text() is cleared :-)

Regards
Luigi Ferraris

Luigi Ferraris

unread,
Dec 7, 2012, 4:47:23 PM12/7/12
to qtcon...@googlegroups.com
Il 07/12/2012 22.23, Dušan D. Majkić ha scritto:
> If it doesn't work, then something like this should work:
> setValidator( HBQVAlidator( {|| .T.} ) )

Noooo I do a mistake in my code. setValidator(NIL) doesn't works!

Using setValidator( HBQVAlidator( {|| .T.} ) ) it works fine, but I
think there are problems related with connected event.

By default I connect returnpressed (with or without validator).
If I set a validator and after I remove it, on empty field return
doesn't works but if I enter any character and press return it works.
I don't know if is normal Qt behaviour or.....

Cheers
Luigi Ferraris


Dušan D. Majkić

unread,
Dec 7, 2012, 6:29:46 PM12/7/12
to qtcon...@googlegroups.com
> If I set a validator and after I remove it, on empty field return doesn't
> works but if I enter any character and press return it works.

I beleive this is a bug in HBQTValidator. Looking at the sources there
is this line

QValidator::State HBQValidator::validate( QString & input, int & pos ) const
{
if( input.isEmpty() )
{
return QValidator::Intermediate;
}
...

If imput string is empty, result is Intermediate. This means that
since it is not QValidator::Accepted,
returnPressed() will not fire.

I belevie that this code that checks for input.isEmpty() should be comented out.

I don't think it is a good idea to hardcode if empty value is always
valid or not. Provieded HBQTValidator block should decide if empty
value is valid or not.

Perhaps I'm missing something(?)

Luigi Ferraris

unread,
Dec 8, 2012, 5:14:10 AM12/8/12
to qtcon...@googlegroups.com
I Dusan, many thanks for your check and explication.
You are right: hardcoding don't must be used. Probably, because we are
testing "QGET" implementation that is a specific "framework" and it
needs to know when an empty string is....intermediate. But HBQValidator
must be used without QGET to perform a good check of it :-)
Anyway I hope this line code will be removed.

Cheers

Luigi Ferraris

Pritpal Bedi

unread,
Dec 8, 2012, 5:45:45 AM12/8/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
>Anyway I hope this line code will be removed. 

Yep, fixed.


Pritpal Bedi

Luigi Ferraris

unread,
Dec 9, 2012, 11:23:59 AM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi Pritpal.

Can you help me to understand when the :fixup( ) block is run? I tried to use but without results.

Cheers
Luigi Ferraris

Pritpal Bedi

unread,
Dec 9, 2012, 11:48:39 AM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi


Can you help me to understand when the :fixup( ) block is run? I tried to use but without results.

Allication code can never and should never run :fixup() method.

It will be called by QLineEdit when an edit has an :intermediate pending to be :validated and 
user tries to change the focus . See how validator.prg validates the buffer on call to fixup().


Pritpal Bedi

Luigi Ferraris

unread,
Dec 9, 2012, 12:52:29 PM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi Pritpal, many thanks for your quickly answer.


>Allication code can never and should never run :fixup() method.
Yes, ok I know.

>It will be called by QLineEdit when an edit has an :intermediate pending to be :validated and 
>user tries to change the focus . See how validator.prg validates the buffer on call to fixup().
I read many times and I tried to use but without any results.
I send you my simple using only HbQt (without Clipper GETSAY). It's a very simple lineediting.
You can search "I Never see here". In many situations, I can't trap something with this method.
Changing focus, enter a bad character and so one.
Can you tell me were I done mystakes?

Cheers
Luigi Ferraris


oop001.zip

Luigi Ferraris

unread,
Dec 9, 2012, 1:42:51 PM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi, I'm very sorry I found the problem.
there is parenthesis in a wrong place
this code
::setValidator( HBQValidator( {|cText,nPos| ::__Validator( cText, nPos ) } ), {|cText| ::__Fixup( cText ) } )
must be
::setValidator( HBQValidator( {|cText,nPos| ::__Validator( cText, nPos ) } , {|cText| ::__Fixup( cText ) } ) )

Cheers
Luigi Ferraris

Pritpal Bedi

unread,
Dec 9, 2012, 1:45:45 PM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi
For debugging such scenarios, never use QMessageBox(), use HB_TRACE(... mechanism.


BTW the code is perfectly working fine as intended, what is your point of discussion ?


Pritpal Bedi 

Pritpal Bedi

unread,
Dec 9, 2012, 3:21:15 PM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi

For your information only:

A SLOT is never subject to stopping/continuation of its execution, only :connect() 
for QEvent_* events do act accoring to return value. For example:

/*
   QReturnPressed
*/
METHOD QReturnPressed() CLASS LINEEDIT

   LOCAL lQtEventStop   := .F.      // .F. means don't stop event hanlder, else .T. STOP see Harbour Changelog

   IF hb_IsBlock( ::bOnReturnPressed )
      EVAL( ::bOnReturnPressed, Self )
   ENDIF

RETURN lQtEventStop

/*
   QTextChanged
*/
METHOD QTextChanged() CLASS LINEEDIT

   LOCAL lQtEventStop   := .F.      // .F. means don't stop event hanlder, else .T. STOP see Harbour Changelog

   IF hb_IsBlock( ::bOnTextChanged )
      EVAL( ::bOnTextChanged, Self )
   ENDIF

RETURN lQtEventStop


Should been :



/*
   QReturnPressed
*/
METHOD QReturnPressed() CLASS LINEEDIT

   IF hb_IsBlock( ::bOnReturnPressed )
      EVAL( ::bOnReturnPressed, Self )
   ENDIF

RETURN NIL

/*
   QTextChanged
*/
METHOD QTextChanged() CLASS LINEEDIT

   IF hb_IsBlock( ::bOnTextChanged )
      EVAL( ::bOnTextChanged, Self )
   ENDIF

RETURN NIL



Pritpal Bedi

Pritpal Bedi

unread,
Dec 9, 2012, 3:27:51 PM12/9/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi

So your prime question is 
Why cannot my class method :fixup() gets fired ? Correct ?

As stated earlier it is visited only when oEdit state is :Intermediate.
In your class, 

/*
   validator
*/
METHOD __Validator( cText, nPos ) CLASS LINEEDIT

   IF nPos == 1 .AND. UPPER( SUBSTR( cText, nPos ) ) != "A"
      RETURN { cText, nPos, .F. }
   ENDIF

RETURN { cText, nPos, .T. }

Either    { cText, nPos, .F. }   means text is INVALID
or          { cText, nPos, .T. }   means test is VALID

So oEdit never enters an INTERMEDIATE state and hence never calls :fixup() method.
Also if oEdit state is INTERMEDIATE, SLOT "ReturnPressed()" will never be fired.

Hope it helps to understand what QValidator() is all about.


Pritpal Bedi

Dusan D. Majkic

unread,
Dec 10, 2012, 5:09:51 AM12/10/12
to qtcon...@googlegroups.com
Fixup() should try to fix invalid value to valid one via provided block. 

It is called when you press Return. Sequence is like this: you press Return, valid() is fired, if valid is not Accepted (eg you don't return .t. from block) than fixup() is called. If you change value in fixup block that new value is validated again. 
--
You received this message because you are subscribed to the Google Groups "QtContribs" group.
To post to this group, send email to qtcon...@googlegroups.com.
To unsubscribe from this group, send email to qtcontribs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/qtcontribs?hl=en.
 
 

Pritpal Bedi

unread,
Dec 10, 2012, 5:21:45 AM12/10/12
to qtcon...@googlegroups.com
Hi


Sequence is like this: you press Return, valid() is fired, if valid is not Accepted (eg you don't return .t. from block) than fixup() is called. If you change value in fixup block that new value is validated again. 
 
Should be read as:

Sequence is like this: you press Return, valid() is fired, if valid is not Accepted (eg you don't return .t. OR .F. from block) than fixup() is called.After call to fixup valid is called again ( always ).



Pritpal Bedi
 

Luigi Ferraris

unread,
Dec 10, 2012, 12:44:00 PM12/10/12
to qtcon...@googlegroups.com
Il 09/12/2012 21.21, Pritpal Bedi ha scritto:
> For your information only:
>
> A SLOT is never subject to stopping/continuation of its execution,
> only :connect()
> for QEvent_* events do act accoring to return value. For example:
>
Ok, you are right.

Il 09/12/2012 18.33, Pritpal Bedi ha scritto:
> Why not you write a "strictly QT" oriented demo.
> I do not know what are you looking for in that appn.
>
I'm sorry, I must write "strictly HbQt"; one source to see "Clipper
Get/Say" and one source for "HBQValidator" usage. For this reason I send
to you an example what I mean.
Program (to see what happen) must be run using "itsname.exe >
tracert.txt" (HB_TRACE used instead of GUI message). I hope this can
help other than me to understand....
Feel free (if you like it) to use/change/publish.

Il 10/12/2012 11.21, Pritpal Bedi ha scritto:
> Should be read as:
>
> Sequence is like this: you press Return, valid() is fired, if valid is
> not Accepted (eg you don't return .t. OR .F. from block) than fixup()
> is called.After call to fixup valid is called again ( always ).
>
Many thanks for this important notice: it makes the difference!

Cheers
Luigi Ferraris

newvalidator.zip

Juan Francolino

unread,
Dec 12, 2012, 10:01:23 AM12/12/12
to qtcon...@googlegroups.com
Hi,

With Marco instructions can build QTCONTRIBS but not securely installed
in Linux as there is no setup permissions on folders / usr / local /
share / harbour / addons and subfolders.

This problem came from the harbour division with hbqt.

Some errors are:

hbmk2: Warning: Copying .. / lib / linux / gcc / libhbqtcore.a to
/ usr / local / share / harbor / addons / hbqt / lib / linux /
gcc / libhbqtcore.a failed
with 5.
hbmk2: Warning: Copying hbqt/qtcore/../hbmk2_qt.hb to
/ usr / local / share /
harbour/addons/hbqt/hbmk2_qt.hb failed with 5.

....

Other errors at the end:

hbmk2: Linking ... hbide / bin / linux / gcc / hbide
hbmk2: Warning: Can not create directory for install target install
/ usr / local / share / harbor / addons / hbide / qtgui.txt.
hbmk2: Warning: Can not create directory for install target install
/ usr / local / share / harbor / addons / hbide / qtcore.txt.
hbmk2: Warning: Can not create directory for install target install
/ usr / local / share / harbor / addons / hbide / qtnetwork.txt.
hbmk2: Warning: Can not create directory for install target install
/ usr / local / share / harbor / addons / hbide / requests.ch.
hbmk2: Warning: Can not create directory for install target install
/ usr / local / share / harbor / addons / hbide / hbide.ch.
hbmk2: Warning: Can not create directory for install target install
/ usr / local / share / harbor / addons / hbide / hbide_v.ch.



Anyone know how to fix.

Thanks in advance.


Regards,

Juan

Luigi Ferraris

unread,
Dec 12, 2012, 4:17:10 PM12/12/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi Pritpal.
I found a strange error/problem.
I know that source code in attachment is "wrong" or is not very good but I think this scenario can create problem with HBQValidator.

Please try compiled source in this way: when form is shown, select all characters and then press DELETE; after this, click on button "check" or use TAB to leave the field.

An error will occur: "no exported method: EVAL"

Pay attention: A) I'm not using hbqtgetsys and B) inputmask is in QT style.

TIA
Luigi Ferraris

test.zip

Luigi Ferraris

unread,
Dec 13, 2012, 3:17:51 PM12/13/12
to qtcon...@googlegroups.com
Il 12/12/2012 22.17, Luigi Ferraris ha scritto:
Hi Pritpal.
I found a strange error/problem.
Well the answer is: when used setInputMask and HBQvalidator, the fixup block it's mandatory.

In example
     oLineedit := QLineEdit()
     oLineEdit:setInputMask( "A-A-A" )
     oLineEdit:setValidator( HBQValidator( <ValidatorBlock>, <FixupBlock> ) )
and <FixupBlock> must exist

This line
     oLineEdit:setValidator( HBQValidator( <ValidatorBlock> ) )
it can't be used because an internal error happens ( see EVALuation <FixUpBlock> )

Cheers

Luigi Ferraris

Pritpal Bedi

unread,
Dec 13, 2012, 4:14:30 PM12/13/12
to qtcon...@googlegroups.com, luigfe...@gmail.com
Hi


Well the answer is: when used setInputMask and HBQvalidator, the fixup block it's mandatory.

Thanks for spotting though it is not the case. Fixed in r92.


Pritpal Bedi 
Reply all
Reply to author
Forward
0 new messages