Qt-interest Archive, January 2007
How to store and retrieve the result from a QValidator
Message 1 in thread
I'm new to QT.
I have a custom validator (inherits from QValidator) on a QLineEdit (on an
editable combo box).
Every time the QLineEdit fires a textEdited signal, I want to know whether
the validator returned Acceptable so I can enable or disable fields
accordingly. This will give the user visual feedback, as he or she types on
whether or not the entry is valid.
By the time textEdited fires, the validation has already taken place. How
can I see what the validator returned from the slot connected to textEdited?
I thought of storing the validation result on the custom validator, but the
virtual validate() method is const.
There must be a "correct" way to do this. Can anyone point me in the right
direction?
(I'm also trying to figure out how to get my combobox to give up focus when
<Enter> is pressed, i.e . to act like <Tab> has been pressed, but I haven't
scoured the docs yet for that one. . . .)
Michael
Message 2 in thread
I think when you set a validator on a QLineEdit, the textEdited
signal gets fired ONLY when the validator accepts the input.
On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
> I'm new to QT.
>
> I have a custom validator (inherits from QValidator) on a QLineEdit
> (on an editable combo box).
>
> Every time the QLineEdit fires a textEdited signal, I want to know
> whether the validator returned Acceptable so I can enable or
> disable fields accordingly. This will give the user visual
> feedback, as he or she types on whether or not the entry is valid.
>
> By the time textEdited fires, the validation has already taken
> place. How can I see what the validator returned from the slot
> connected to textEdited?
>
> I thought of storing the validation result on the custom validator,
> but the virtual validate() method is const.
>
> There must be a "correct" way to do this. Can anyone point me in
> the right direction?
>
> (I'm also trying to figure out how to get my combobox to give up
> focus when <Enter> is pressed, i.e . to act like <Tab> has been
> pressed, but I haven't scoured the docs yet for that one. . . .)
>
> Michael
Bruno Trindade
Señor Software Engineer
bruno@xxxxxxxxx
Message 3 in thread
Bruno and Thomas,
Thanks for the feedback.
I believe editingFinished() fires only if the validator returns Acceptable.
But for my custom validator, textEdited() fires after every keystroke.
I inserted some calls to qDebug(). Here's my output. The validator checks
whether the input is an existing directory, so c:\q is invalid, but c:\qt is
valid.
validate() returning Intermediate
textEditing fired on text: [ "c" ]
validate() returning Acceptable
validate() returning Acceptable
textEditing fired on text: [ "c:" ]
validate() returning Acceptable
validate() returning Acceptable
textEditing fired on text: [ "c:/" ]
validate() returning Acceptable
validate() returning Intermediate
textEditing fired on text: [ "c:/q" ]
validate() returning Acceptable
textEditing fired on text: [ "c:/qt" ]
I'm also not sure why validate() is getting called twice on each edit.
Here's my very simple validator code:
Declaration:
class DirectoryExistsValidator : public QValidator
{
Q_OBJECT
public:
DirectoryExistsValidator(QObject *parent);
~DirectoryExistsValidator();
void fixup( QString &input ) const;
State validate( QString &input, int &pos ) const;
};
Implementation:
DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
: QValidator(parent)
{
}
DirectoryExistsValidator::~DirectoryExistsValidator()
{
}
void DirectoryExistsValidator::fixup( QString &input ) const
{
}
QValidator::State DirectoryExistsValidator::validate( QString &input, int
&pos ) const
{
QDir dirInput(input);
if( dirInput.exists() )
{
qDebug( "validate() returning Acceptable" );
return QValidator::Acceptable;
}
else
{
qDebug( "validate() returning Intermediate" );
return QValidator::Intermediate;
}
}
Michael
On 1/18/07, Bruno Trindade <bruno@xxxxxxxxx> wrote:
>
> I think when you set a validator on a QLineEdit, the textEdited signal
> gets fired ONLY when the validator accepts the input.
>
> On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
>
> I'm new to QT.
>
> I have a custom validator (inherits from QValidator) on a QLineEdit (on an
> editable combo box).
>
> Every time the QLineEdit fires a textEdited signal, I want to know whether
> the validator returned Acceptable so I can enable or disable fields
> accordingly. This will give the user visual feedback, as he or she types on
> whether or not the entry is valid.
>
> By the time textEdited fires, the validation has already taken place. How
> can I see what the validator returned from the slot connected to textEdited?
>
> I thought of storing the validation result on the custom validator, but
> the virtual validate() method is const.
>
> There must be a "correct" way to do this. Can anyone point me in the
> right direction?
>
> (I'm also trying to figure out how to get my combobox to give up focus
> when <Enter> is pressed, i.e . to act like <Tab> has been pressed, but I
> haven't scoured the docs yet for that one. . . .)
>
> Michael
>
>
> Bruno Trindade
> Señor Software Engineer
> bruno@xxxxxxxxx
>
>
>
>
Message 4 in thread
Michael,
QValidator::Intermediate does not mark any input as incorrect, it just
says that it is still valid at the moment. What you need to return if a
directory does not exist is QValidator::Invalid - however, I think your
current implementation won't allow any input at all this way. You would
have to return QValidator::Intermediate whenever the current users input
might lead to a correct directory, and QValidator::Invalid when the
users input is definitely wrong.
Thomas
Michael Hardt schrieb:
> Bruno and Thomas,
>
> Thanks for the feedback.
>
> I believe editingFinished() fires only if the validator returns
> Acceptable. But for my custom validator, textEdited() fires after every
> keystroke.
>
> I inserted some calls to qDebug(). Here's my output. The validator
> checks whether the input is an existing directory, so c:\q is invalid,
> but c:\qt is valid.
>
> validate() returning Intermediate
> textEditing fired on text: [ "c" ]
>
> validate() returning Acceptable
> validate() returning Acceptable
> textEditing fired on text: [ "c:" ]
>
> validate() returning Acceptable
> validate() returning Acceptable
> textEditing fired on text: [ "c:/" ]
>
> validate() returning Acceptable
> validate() returning Intermediate
> textEditing fired on text: [ "c:/q" ]
>
> validate() returning Acceptable
> textEditing fired on text: [ "c:/qt" ]
>
> I'm also not sure why validate() is getting called twice on each edit.
> Here's my very simple validator code:
>
> Declaration:
> class DirectoryExistsValidator : public QValidator
> {
> Q_OBJECT
>
> public:
> DirectoryExistsValidator(QObject *parent);
> ~DirectoryExistsValidator();
> void fixup( QString &input ) const;
> State validate( QString &input, int &pos ) const;
> };
>
> Implementation:
> DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
> : QValidator(parent)
> {
> }
>
> DirectoryExistsValidator::~DirectoryExistsValidator()
> {
> }
>
> void DirectoryExistsValidator::fixup( QString &input ) const
> {
> }
>
> QValidator::State DirectoryExistsValidator::validate( QString &input,
> int &pos ) const
> {
> QDir dirInput(input);
> if( dirInput.exists() )
> {
> qDebug( "validate() returning Acceptable" );
> return QValidator::Acceptable;
> }
> else
> {
> qDebug( "validate() returning Intermediate" );
> return QValidator::Intermediate;
> }
> }
>
> Michael
>
>
>
>
>
>
> On 1/18/07, *Bruno Trindade* < bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>>
> wrote:
>
> I think when you set a validator on a QLineEdit, the textEdited
> signal gets fired ONLY when the validator accepts the input.
>
>
> On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
>
>> I'm new to QT.
>>
>> I have a custom validator (inherits from QValidator) on a
>> QLineEdit (on an editable combo box).
>>
>> Every time the QLineEdit fires a textEdited signal, I want to know
>> whether the validator returned Acceptable so I can enable or
>> disable fields accordingly. This will give the user visual
>> feedback, as he or she types on whether or not the entry is valid.
>>
>> By the time textEdited fires, the validation has already taken
>> place. How can I see what the validator returned from the slot
>> connected to textEdited?
>>
>> I thought of storing the validation result on the custom
>> validator, but the virtual validate() method is const.
>>
>> There must be a "correct" way to do this. Can anyone point me in
>> the right direction?
>>
>> (I'm also trying to figure out how to get my combobox to give up
>> focus when <Enter> is pressed, i.e . to act like <Tab> has been
>> pressed, but I haven't scoured the docs yet for that one. . . .)
>>
>> Michael
>
> Bruno Trindade
> Señor Software Engineer
> bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>
>
>
>
>
--
[ signature omitted ]
Message 5 in thread
I concur--but isn't that what I'm doing? I'm never returning Invalid; I'm
returning Intermediate when the directory doesn't exist; I'm returning
Acceptable when it does.
Still, I'm not sure how to go about capturing that return value (apart from
setting a global) in order to update my widgets to reflect whether the
Validator returned Intermediate or Acceptable.
Michael
>
>
>
>
> On 1/18/07, Thomas Dähling <t.daehling@xxxxxxxxxxxxxx> wrote:
> >
> > Michael,
> >
> > QValidator::Intermediate does not mark any input as incorrect, it just
> > says that it is still valid at the moment. What you need to return if a
> > directory does not exist is QValidator::Invalid - however, I think your
> > current implementation won't allow any input at all this way. You would
> > have to return QValidator::Intermediate whenever the current users input
> > might lead to a correct directory, and QValidator::Invalid when the
> > users input is definitely wrong.
> >
> > Thomas
> >
> > Michael Hardt schrieb:
> > > Bruno and Thomas,
> > >
> > > Thanks for the feedback.
> > >
> > > I believe editingFinished() fires only if the validator returns
> > > Acceptable. But for my custom validator, textEdited() fires after
> > every
> > > keystroke.
> > >
> > > I inserted some calls to qDebug(). Here's my output. The validator
> > > checks whether the input is an existing directory, so c:\q is invalid,
> >
> > > but c:\qt is valid.
> > >
> > > validate() returning Intermediate
> > > textEditing fired on text: [ "c" ]
> > >
> > > validate() returning Acceptable
> > > validate() returning Acceptable
> > > textEditing fired on text: [ "c:" ]
> > >
> > > validate() returning Acceptable
> > > validate() returning Acceptable
> > > textEditing fired on text: [ "c:/" ]
> > >
> > > validate() returning Acceptable
> > > validate() returning Intermediate
> > > textEditing fired on text: [ "c:/q" ]
> > >
> > > validate() returning Acceptable
> > > textEditing fired on text: [ "c:/qt" ]
> > >
> > > I'm also not sure why validate() is getting called twice on each edit.
> >
> > > Here's my very simple validator code:
> > >
> > > Declaration:
> > > class DirectoryExistsValidator : public QValidator
> > > {
> > > Q_OBJECT
> > >
> > > public:
> > > DirectoryExistsValidator(QObject *parent);
> > > ~DirectoryExistsValidator();
> > > void fixup( QString &input ) const;
> > > State validate( QString &input, int &pos ) const;
> > > };
> > >
> > > Implementation:
> > > DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
> > > : QValidator(parent)
> > > {
> > > }
> > >
> > > DirectoryExistsValidator::~DirectoryExistsValidator()
> > > {
> > > }
> > >
> > > void DirectoryExistsValidator::fixup( QString &input ) const
> > > {
> > > }
> > >
> > > QValidator::State DirectoryExistsValidator::validate( QString &input,
> > > int &pos ) const
> > > {
> > > QDir dirInput(input);
> > > if( dirInput.exists() )
> > > {
> > > qDebug( "validate() returning Acceptable" );
> > > return QValidator::Acceptable;
> > > }
> > > else
> > > {
> > > qDebug( "validate() returning Intermediate" );
> > > return QValidator::Intermediate;
> > > }
> > > }
> > >
> > > Michael
> > >
> > >
> > >
> > >
> > >
> > >
> > > On 1/18/07, *Bruno Trindade* < bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx
> > >>
> > > wrote:
> > >
> > > I think when you set a validator on a QLineEdit, the textEdited
> > > signal gets fired ONLY when the validator accepts the input.
> > >
> > >
> > > On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
> > >
> > >> I'm new to QT.
> > >>
> > >> I have a custom validator (inherits from QValidator) on a
> > >> QLineEdit (on an editable combo box).
> > >>
> > >> Every time the QLineEdit fires a textEdited signal, I want to
> > know
> > >> whether the validator returned Acceptable so I can enable or
> > >> disable fields accordingly. This will give the user visual
> > >> feedback, as he or she types on whether or not the entry is
> > valid.
> > >>
> > >> By the time textEdited fires, the validation has already taken
> > >> place. How can I see what the validator returned from the slot
> > >> connected to textEdited?
> > >>
> > >> I thought of storing the validation result on the custom
> > >> validator, but the virtual validate() method is const.
> > >>
> > >> There must be a "correct" way to do this. Can anyone point me in
> >
> > >> the right direction?
> > >>
> > >> (I'm also trying to figure out how to get my combobox to give up
> > >> focus when <Enter> is pressed, i.e . to act like <Tab> has been
> > >> pressed, but I haven't scoured the docs yet for that one. . . .)
> > >>
> > >> Michael
> > >
> > > Bruno Trindade
> > > Señor Software Engineer
> > > bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>
> > >
> > >
> > >
> > >
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> >
> >
>
Message 6 in thread
My bad, I somewhat pointed you into the wrong direction. Sorry for that.
However, here is a solution that should work for you:
Instead of setting your validator with QLineEdit::setValidator() you
could just create an instance of your validator in a custom slot and
connect the textEdited() signal of your QLineEdit to that slot.
The slot could be implemented like this:
void myclass::validateField(QString &text)
{
DirectoryExistsValidator validator;
QValidator::State state;
state = validator.validate(text, 0);
if (state == QValidator::Intermediate
|| state ==QValidator::Acceptable)
{
setText(text);
}
}
Hope this helps you now :-)
/Thomas
Michael Hardt schrieb:
> I concur--but that's what I'm doing isn't it? I'm never returning
> Invalid; I'm returning Intermediate when the directory doesn't exist;
> I'm returning Acceptable when it does.
>
> Still, I'm not sure how to go about capturing that return value (apart
> from setting a global) in order to update my widgets to reflect whether
> the Validator returned Intermeditate or Acceptable.
>
> Michael
>
>
> On 1/18/07, *Thomas Dähling* <t.daehling@xxxxxxxxxxxxxx
> <mailto:t.daehling@xxxxxxxxxxxxxx>> wrote:
>
> Michael,
>
> QValidator::Intermediate does not mark any input as incorrect, it just
> says that it is still valid at the moment. What you need to return if a
> directory does not exist is QValidator::Invalid - however, I think your
> current implementation won't allow any input at all this way. You would
> have to return QValidator::Intermediate whenever the current users input
> might lead to a correct directory, and QValidator::Invalid when the
> users input is definitely wrong.
>
> Thomas
>
> Michael Hardt schrieb:
> > Bruno and Thomas,
> >
> > Thanks for the feedback.
> >
> > I believe editingFinished() fires only if the validator returns
> > Acceptable. But for my custom validator, textEdited() fires
> after every
> > keystroke.
> >
> > I inserted some calls to qDebug(). Here's my output. The validator
> > checks whether the input is an existing directory, so c:\q is
> invalid,
> > but c:\qt is valid.
> >
> > validate() returning Intermediate
> > textEditing fired on text: [ "c" ]
> >
> > validate() returning Acceptable
> > validate() returning Acceptable
> > textEditing fired on text: [ "c:" ]
> >
> > validate() returning Acceptable
> > validate() returning Acceptable
> > textEditing fired on text: [ "c:/" ]
> >
> > validate() returning Acceptable
> > validate() returning Intermediate
> > textEditing fired on text: [ "c:/q" ]
> >
> > validate() returning Acceptable
> > textEditing fired on text: [ "c:/qt" ]
> >
> > I'm also not sure why validate() is getting called twice on each
> edit.
> > Here's my very simple validator code:
> >
> > Declaration:
> > class DirectoryExistsValidator : public QValidator
> > {
> > Q_OBJECT
> >
> > public:
> > DirectoryExistsValidator(QObject *parent);
> > ~DirectoryExistsValidator();
> > void fixup( QString &input ) const;
> > State validate( QString &input, int &pos ) const;
> > };
> >
> > Implementation:
> > DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
> > : QValidator(parent)
> > {
> > }
> >
> > DirectoryExistsValidator::~DirectoryExistsValidator()
> > {
> > }
> >
> > void DirectoryExistsValidator::fixup( QString &input ) const
> > {
> > }
> >
> > QValidator::State DirectoryExistsValidator::validate( QString &input,
> > int &pos ) const
> > {
> > QDir dirInput(input);
> > if( dirInput.exists() )
> > {
> > qDebug( "validate() returning Acceptable" );
> > return QValidator::Acceptable;
> > }
> > else
> > {
> > qDebug( "validate() returning Intermediate" );
> > return QValidator::Intermediate;
> > }
> > }
> >
> > Michael
> >
> >
> >
> >
> >
> >
> > On 1/18/07, *Bruno Trindade* < bruno@xxxxxxxxx
> <mailto:bruno@xxxxxxxxx> <mailto:bruno@xxxxxxxxx
> <mailto:bruno@xxxxxxxxx>>>
> > wrote:
> >
> > I think when you set a validator on a QLineEdit, the textEdited
> > signal gets fired ONLY when the validator accepts the input.
> >
> >
> > On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
> >
> >> I'm new to QT.
> >>
> >> I have a custom validator (inherits from QValidator) on a
> >> QLineEdit (on an editable combo box).
> >>
> >> Every time the QLineEdit fires a textEdited signal, I want
> to know
> >> whether the validator returned Acceptable so I can enable or
> >> disable fields accordingly. This will give the user visual
> >> feedback, as he or she types on whether or not the entry is
> valid.
> >>
> >> By the time textEdited fires, the validation has already taken
> >> place. How can I see what the validator returned from the slot
> >> connected to textEdited?
> >>
> >> I thought of storing the validation result on the custom
> >> validator, but the virtual validate() method is const.
> >>
> >> There must be a "correct" way to do this. Can anyone point
> me in
> >> the right direction?
> >>
> >> (I'm also trying to figure out how to get my combobox to give up
> >> focus when <Enter> is pressed, i.e . to act like <Tab> has been
> >> pressed, but I haven't scoured the docs yet for that one. . . .)
> >>
> >> Michael
> >
> > Bruno Trindade
> > Señor Software Engineer
> > bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>
> <mailto:bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>>
> >
> >
> >
> >
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> <mailto:qt-interest-request@xxxxxxxxxxxxx> with "unsubscribe" in the
> subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 7 in thread
Ah yes, sorry about that. It's not clear to me why you're interested
in Intermediate states? I have used the validator with the textEdited
() signal and a slot in the following way:
void /* slot */
MyWidget::onTextChanged() {
loginButton->setEnabled(userNameTextField->hasAcceptableInput()
&& !passwordTextField->text().isEmpty());
}
Is this the type of behavior you're looking for, or am I missing
something?
On Jan 18, 2007, at 12:48 PM, Michael Hardt wrote:
> Bruno and Thomas,
>
> Thanks for the feedback.
>
> I believe editingFinished() fires only if the validator returns
> Acceptable. But for my custom validator, textEdited() fires after
> every keystroke.
>
> I inserted some calls to qDebug(). Here's my output. The
> validator checks whether the input is an existing directory, so c:
> \q is invalid, but c:\qt is valid.
>
> validate() returning Intermediate
> textEditing fired on text: [ "c" ]
>
> validate() returning Acceptable
> validate() returning Acceptable
> textEditing fired on text: [ "c:" ]
>
> validate() returning Acceptable
> validate() returning Acceptable
> textEditing fired on text: [ "c:/" ]
>
> validate() returning Acceptable
> validate() returning Intermediate
> textEditing fired on text: [ "c:/q" ]
>
> validate() returning Acceptable
> textEditing fired on text: [ "c:/qt" ]
>
> I'm also not sure why validate() is getting called twice on each
> edit. Here's my very simple validator code:
>
> Declaration:
> class DirectoryExistsValidator : public QValidator
> {
> Q_OBJECT
>
> public:
> DirectoryExistsValidator(QObject *parent);
> ~DirectoryExistsValidator();
> void fixup( QString &input ) const;
> State validate( QString &input, int &pos ) const;
> };
>
> Implementation:
> DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
> : QValidator(parent)
> {
> }
>
> DirectoryExistsValidator::~DirectoryExistsValidator()
> {
> }
>
> void DirectoryExistsValidator::fixup( QString &input ) const
> {
> }
>
> QValidator::State DirectoryExistsValidator::validate( QString
> &input, int &pos ) const
> {
> QDir dirInput(input);
> if( dirInput.exists() )
> {
> qDebug( "validate() returning Acceptable" );
> return QValidator::Acceptable;
> }
> else
> {
> qDebug( "validate() returning Intermediate" );
> return QValidator::Intermediate;
> }
> }
>
> Michael
>
>
>
>
>
>
> On 1/18/07, Bruno Trindade < bruno@xxxxxxxxx> wrote:
> I think when you set a validator on a QLineEdit, the textEdited
> signal gets fired ONLY when the validator accepts the input.
>
>
> On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
>
>> I'm new to QT.
>>
>> I have a custom validator (inherits from QValidator) on a
>> QLineEdit (on an editable combo box).
>>
>> Every time the QLineEdit fires a textEdited signal, I want to know
>> whether the validator returned Acceptable so I can enable or
>> disable fields accordingly. This will give the user visual
>> feedback, as he or she types on whether or not the entry is valid.
>>
>> By the time textEdited fires, the validation has already taken
>> place. How can I see what the validator returned from the slot
>> connected to textEdited?
>>
>> I thought of storing the validation result on the custom
>> validator, but the virtual validate() method is const.
>>
>> There must be a "correct" way to do this. Can anyone point me in
>> the right direction?
>>
>> (I'm also trying to figure out how to get my combobox to give up
>> focus when <Enter> is pressed, i.e . to act like <Tab> has been
>> pressed, but I haven't scoured the docs yet for that one. . . .)
>>
>> Michael
>
> Bruno Trindade
> Señor Software Engineer
> bruno@xxxxxxxxx
>
>
>
>
Bruno Trindade
Señor Software Engineer
bruno@xxxxxxxxx
Message 8 in thread
Oh right, forgot about that member function :-)
That does make my slot suggestion obsolete.
Bruno Trindade schrieb:
> Ah yes, sorry about that. It's not clear to me why you're interested in
> Intermediate states? I have used the validator with the textEdited()
> signal and a slot in the following way:
>
> void /* slot */
> MyWidget::onTextChanged() {
> loginButton->setEnabled(userNameTextField->hasAcceptableInput() &&
> !passwordTextField->text().isEmpty());
> }
>
> Is this the type of behavior you're looking for, or am I missing something?
>
>
> On Jan 18, 2007, at 12:48 PM, Michael Hardt wrote:
>
>> Bruno and Thomas,
>>
>> Thanks for the feedback.
>>
>> I believe editingFinished() fires only if the validator returns
>> Acceptable. But for my custom validator, textEdited() fires after
>> every keystroke.
>>
>> I inserted some calls to qDebug(). Here's my output. The validator
>> checks whether the input is an existing directory, so c:\q is invalid,
>> but c:\qt is valid.
>>
>> validate() returning Intermediate
>> textEditing fired on text: [ "c" ]
>>
>> validate() returning Acceptable
>> validate() returning Acceptable
>> textEditing fired on text: [ "c:" ]
>>
>> validate() returning Acceptable
>> validate() returning Acceptable
>> textEditing fired on text: [ "c:/" ]
>>
>> validate() returning Acceptable
>> validate() returning Intermediate
>> textEditing fired on text: [ "c:/q" ]
>>
>> validate() returning Acceptable
>> textEditing fired on text: [ "c:/qt" ]
>>
>> I'm also not sure why validate() is getting called twice on each
>> edit. Here's my very simple validator code:
>>
>> Declaration:
>> class DirectoryExistsValidator : public QValidator
>> {
>> Q_OBJECT
>>
>> public:
>> DirectoryExistsValidator(QObject *parent);
>> ~DirectoryExistsValidator();
>> void fixup( QString &input ) const;
>> State validate( QString &input, int &pos ) const;
>> };
>>
>> Implementation:
>> DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
>> : QValidator(parent)
>> {
>> }
>>
>> DirectoryExistsValidator::~DirectoryExistsValidator()
>> {
>> }
>>
>> void DirectoryExistsValidator::fixup( QString &input ) const
>> {
>> }
>>
>> QValidator::State DirectoryExistsValidator::validate( QString &input,
>> int &pos ) const
>> {
>> QDir dirInput(input);
>> if( dirInput.exists() )
>> {
>> qDebug( "validate() returning Acceptable" );
>> return QValidator::Acceptable;
>> }
>> else
>> {
>> qDebug( "validate() returning Intermediate" );
>> return QValidator::Intermediate;
>> }
>> }
>>
>> Michael
>>
>>
>>
>>
>>
>>
>> On 1/18/07, *Bruno Trindade* < bruno@xxxxxxxxx
>> <mailto:bruno@xxxxxxxxx>> wrote:
>>
>> I think when you set a validator on a QLineEdit, the textEdited
>> signal gets fired ONLY when the validator accepts the input.
>>
>>
>> On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
>>
>>> I'm new to QT.
>>>
>>> I have a custom validator (inherits from QValidator) on a
>>> QLineEdit (on an editable combo box).
>>>
>>> Every time the QLineEdit fires a textEdited signal, I want to
>>> know whether the validator returned Acceptable so I can enable or
>>> disable fields accordingly. This will give the user visual
>>> feedback, as he or she types on whether or not the entry is valid.
>>>
>>> By the time textEdited fires, the validation has already taken
>>> place. How can I see what the validator returned from the slot
>>> connected to textEdited?
>>>
>>> I thought of storing the validation result on the custom
>>> validator, but the virtual validate() method is const.
>>>
>>> There must be a "correct" way to do this. Can anyone point me in
>>> the right direction?
>>>
>>> (I'm also trying to figure out how to get my combobox to give up
>>> focus when <Enter> is pressed, i.e . to act like <Tab> has been
>>> pressed, but I haven't scoured the docs yet for that one. . . .)
>>>
>>> Michael
>>
>> Bruno Trindade
>> Señor Software Engineer
>> bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>
>>
>>
>>
>>
>
> Bruno Trindade
> Señor Software Engineer
> bruno@xxxxxxxxx <mailto:bruno@xxxxxxxxx>
>
>
>
--
[ signature omitted ]
Message 9 in thread
Yes!
Again, thank you both. Thomas's suggestion works nicely, but
hasAcceptableInput() is exactly what I was looking for.
Michael
On 1/18/07, Thomas Dähling <t.daehling@xxxxxxxxxxxxxx> wrote:
>
> Oh right, forgot about that member function :-)
>
> That does make my slot suggestion obsolete.
>
> Bruno Trindade schrieb:
> > Ah yes, sorry about that. It's not clear to me why you're interested in
> > Intermediate states? I have used the validator with the textEdited()
> > signal and a slot in the following way:
> >
> > void /* slot */
> > MyWidget::onTextChanged() {
> > loginButton->setEnabled(userNameTextField->hasAcceptableInput() &&
> > !passwordTextField->text().isEmpty());
> > }
> >
> > Is this the type of behavior you're looking for, or am I missing
> something?
> >
> >
> > On Jan 18, 2007, at 12:48 PM, Michael Hardt wrote:
> >
> >> Bruno and Thomas,
> >>
> >> Thanks for the feedback.
> >>
> >> I believe editingFinished() fires only if the validator returns
> >> Acceptable. But for my custom validator, textEdited() fires after
> >> every keystroke.
> >>
> >> I inserted some calls to qDebug(). Here's my output. The validator
> >> checks whether the input is an existing directory, so c:\q is invalid,
> >> but c:\qt is valid.
> >>
> >> validate() returning Intermediate
> >> textEditing fired on text: [ "c" ]
> >>
> >> validate() returning Acceptable
> >> validate() returning Acceptable
> >> textEditing fired on text: [ "c:" ]
> >>
> >> validate() returning Acceptable
> >> validate() returning Acceptable
> >> textEditing fired on text: [ "c:/" ]
> >>
> >> validate() returning Acceptable
> >> validate() returning Intermediate
> >> textEditing fired on text: [ "c:/q" ]
> >>
> >> validate() returning Acceptable
> >> textEditing fired on text: [ "c:/qt" ]
> >>
> >> I'm also not sure why validate() is getting called twice on each
> >> edit. Here's my very simple validator code:
> >>
> >> Declaration:
> >> class DirectoryExistsValidator : public QValidator
> >> {
> >> Q_OBJECT
> >>
> >> public:
> >> DirectoryExistsValidator(QObject *parent);
> >> ~DirectoryExistsValidator();
> >> void fixup( QString &input ) const;
> >> State validate( QString &input, int &pos ) const;
> >> };
> >>
> >> Implementation:
> >> DirectoryExistsValidator::DirectoryExistsValidator(QObject *parent)
> >> : QValidator(parent)
> >> {
> >> }
> >>
> >> DirectoryExistsValidator::~DirectoryExistsValidator()
> >> {
> >> }
> >>
> >> void DirectoryExistsValidator::fixup( QString &input ) const
> >> {
> >> }
> >>
> >> QValidator::State DirectoryExistsValidator::validate( QString &input,
> >> int &pos ) const
> >> {
> >> QDir dirInput(input);
> >> if( dirInput.exists() )
> >> {
> >> qDebug( "validate() returning Acceptable" );
> >> return QValidator::Acceptable;
> >> }
> >> else
> >> {
> >> qDebug( "validate() returning Intermediate" );
> >> return QValidator::Intermediate;
> >> }
> >> }
> >>
> >> Michael
> >>
> >>
> >>
> >>
> >>
> >>
> >> On 1/18/07, *Bruno Trindade* < bruno@xxxxxxxxx
> >> <mailto:bruno@xxxxxxxxx>> wrote:
> >>
> >> I think when you set a validator on a QLineEdit, the textEdited
> >> signal gets fired ONLY when the validator accepts the input.
> >>
> >>
> >> On Jan 18, 2007, at 12:24 PM, Michael Hardt wrote:
> >>
> >>> I'm new to QT.
> >>>
> >>> I have a custom validator (inherits from QValidator) on a
> >>> QLineEdit (on an editable combo box).
> >>>
> >>> Every time the QLineEdit fires a textEdited signal, I want to
> >>> know whether the validator returned Acceptable so I can enable or
> >>> disable fields accordingly. This will give the user visual
> >>> feedback, as he or she types on whether or not the entry is valid.
> >>>
> >>> By the time textEdited fires, the validation has already taken
> >>> place. How can I see what the validator returned from the slot
> >>> connected to textEdited?
> >>>
> >>> I thought of storing the validation result on the custom
> >>> validator, but the virtual validate() method is const.
> >>>
> >>> There must be a "correct" way to do this. Can anyone point me in
> >>> the right direction?
> >>>
> >>> (I'm also trying to figure out how to get my combobox to give up
> >>> focus when <Enter> is pressed, i.e . to act like <Tab> has been
> >>> pressed, but I haven't scoured the docs yet for that one. . . .)
> >>>
> >>> Michael
> >>
> >> Bruno Trindade
> >> Señor Software Engineer
> >> bruno@xxxxxxxxx <mailto: bruno@xxxxxxxxx>
> >>
> >>
> >>
> >>
> >
> > Bruno Trindade
> > Señor Software Engineer
> > bruno@xxxxxxxxx <mailto: bruno@xxxxxxxxx>
> >
> >
> >
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 10 in thread
Hi,
if you set a validator for a QLineEdit, the QLineEdit will only accept
valid input, i.e. if you set a QIntValidator then the QLineEdit will
only accept characters 0 to 9 as input, as long as the number entered is
>= or <= the min/max values you set for QValidator.
Thomas
Michael Hardt schrieb:
> I'm new to QT.
>
> I have a custom validator (inherits from QValidator) on a QLineEdit (on
> an editable combo box).
>
> Every time the QLineEdit fires a textEdited signal, I want to know
> whether the validator returned Acceptable so I can enable or disable
> fields accordingly. This will give the user visual feedback, as he or
> she types on whether or not the entry is valid.
>
> By the time textEdited fires, the validation has already taken place.
> How can I see what the validator returned from the slot connected to
> textEdited?
>
> I thought of storing the validation result on the custom validator, but
> the virtual validate() method is const.
>
> There must be a "correct" way to do this. Can anyone point me in the
> right direction?
>
> (I'm also trying to figure out how to get my combobox to give up focus
> when <Enter> is pressed, i.e . to act like <Tab> has been pressed, but I
> haven't scoured the docs yet for that one. . . .)
>
> Michael
--
[ signature omitted ]