HBQValidator little question.

43 views
Skip to first unread message

Luigi Ferraris

unread,
Aug 12, 2023, 6:27:57 AM8/12/23
to QtContribs
Hi Pritpal,
I'm doing some test using HBQValidator.
I'm reading hbqt_hbqvalidator.cpp and I found a difference,
between "fixup" and "validate" functions, so I'm asking to you why.

Snipped code (bold the difference)

void HBQValidator::fixup( QString & input ) const
   PHB_ITEM p0 = hb_itemPutStrUTF8( NULL, input.toLatin1().data() );

QValidator::State HBQValidator::validate( QString & input, int & pos ) const
   PHB_ITEM p0 = hb_itemPutStrUTF8( NULL, input.toUtf8().data() );

   
In the first one input.toLatin1().data() is used
while in the second one input.toUtf8().data() is used,
but (basically) I think they need the same thing.

Reading online Qt docs about toLatin1, it seems more appropriate
the usage of input.toUtf8().data(), but it's a very little opinion.
Anyhow, why this difference?

Best regards
Luigi Ferraris

Pritpal Bedi

unread,
Aug 12, 2023, 3:53:38 PM8/12/23
to QtContribs
Hi Luigi

Do not remeber why but there may had been some issue when compiling the sources. Convert the 2nd as first in the source, compile and test,  and check the results. If ok I will commit.


Pritpal Bedi
a student of software analysis & concepts

Luigi Ferraris

unread,
Aug 13, 2023, 2:10:25 PM8/13/23
to qtcon...@googlegroups.com
Hi Pritpal,
many thank for the answer.


Il 12/08/2023 21:53, Pritpal Bedi ha scritto:
Hi Luigi

Do not remeber why but there may had been some issue when compiling the sources. Convert the 2nd as first in the source, compile and test,  and check the results. If ok I will commit.


Probably, due to my bad English grammar: I was thinking to convert the first as second. On the other hand, hb_itemPutStrUTF8 is used (if I understand its behaviour)
In other words always input.toUtf8().data()

Regards
Luigi

Luigi Ferraris

unread,
Aug 18, 2023, 9:19:16 AM8/18/23
to QtContribs
I Pritpal,
I spent some days to investigate and coding...

In attachement, you will find a simple program and an update of HBQValidator, if you find it worthwhile.

The program is very simple: based on the style (see comboBox) the lineEdit text is different both using setText while editing.
Regarding to OS, Harbour and Qt, remember that I'm Italian.
ALERT: you must replace lw_Trace(...) function with your preferred, to write text into an external file.
ALERT_2: I've aligned Harbour codepage to OS (see ThisInit() ) otherwise (f.e.) "à" is "..." translated
WARNING: to build program, I add this lines to .hbp
-pflag=-qtver=0x040500
-pflag=-qtmodule=qtgui
-pflag=-qthdocdir=../doc/
-i.
-i${HB_WITH_QT}
-cflag=-std=c++11



Before describing the differences between HBQValidator and XFQValidator, I report below some observations made using the program

A) solution: AFAIK the normal way if I understand Qt docs.
Warning: to run this solution, you need to change from "if( 0==1 )" to "if( 0==0 )" in oop001.prg

1) It seems that using ::setText( txt ) where txt is equal to ::text()
the  ::validate(...) is NOT fired on; you need to follow 3.1)

2) using :setText( txt ) where ::validate(...) returns QValidator::Intermediate (from HbQValidator pov is NIL or {text, pos, NIL))
the ::fixup(...) function is NOT fired on, I think due to Qt (only my version???)

3.1) only when you leave the field (i.e. press <TAB> or <RETURN>), the ::fixup() is execute
and ::validate() functions is execute 2 times (I don't know why)

but

3.2) while you are editing the field and for some reason ::validate() returns QValidator::Intermediate, no ::fixup() call is execute.
You must leave the field, see 3.1) , I think due to Qt (only my version???)

B) solution: using a trick.
Warning: to run this solution, you need to change from "if( 0==0 )" to "if( 0==1 )" in oop001.prg
The trick is to call ::fixup() "code" into ::validate() :-)) but remember the 1)
The difference with "A) solution" is that while you are edit the field is immediately update.
Obviously, the ::fixup() "code" is call everytime ::validate() is execute, so the ::fixup() procedure call is never do.
This seems to be (more or less) the solution adopted/suggested by PyQt.

HBQValidator vs XFQValidator differences (I have used different names only to be able to run both versions).

a) I used input.toUtf8().data() for both ::validate() and ::fixup() without problems,
People speaking different language than mine, can build and run program and report problems.

b) A parent can be given, so the constructor can be
   xxValidator() read b.1)
   xxValidator( parent ) read b.1)
   xxValidator( validateBlock )
   xxValidator( validateBlock, parent )
   xxValidator( validateBlock, fixupBlock )  as current version
   xxValidator( validateBlock, fixupBlock, parent )
   
b.1) due to constructors, there is hbSetBlocks( validateBlock, fixupBlock )
ALERT usage: hbSetBlocks() removes both validate and fixup block
             hbSetBlocks( validateBlock ) removes fixup and set validate block
             hbSetBlocks( NIL, fixupBlock ) removes validate and set fixup block
             hbSetBlocks( validateBlock, fixupBlock ) set both blocks
             
             
Little aside question:
why these declarations
   PHB_ITEM pValidBlk;
   PHB_ITEM pFixupBlk;

must be declared as "public" within xxxx.h file?
I tried
   private:
   PHB_ITEM pValidBlk;
   PHB_ITEM pFixupBlk;

but I get compilation errors. I'm not a C programmer :-))

Best regards
Luigi
xfqvalidator.zip
Reply all
Reply to author
Forward
0 new messages