[PyQt] QValidator.validate() returns TypeError: invalid result type
Phil Thompson
phil at riverbankcomputing.com
Sun Aug 15 09:15:30 BST 2010
On Sat, 14 Aug 2010 20:16:30 -0400, Eric Frederich
<eric.frederich at gmail.com> wrote:
> Whoops, didn't realize I took this conversation off the mailing list.
>
> So, does this mean it is not possible then to have a validator in
Python2
> fix the string?
No. The default API for Python2 means that the (mutable) QString you pass
is modified. The default API for Python3 means that a modified copy of the
(immutable) str is returned.
If you want to use the Python2 API in Python3 (or vice versa) you have to
explicitly set the API version (but the docstrings will not change).
Phil
> On Sat, Aug 14, 2010 at 7:12 AM, Phil Thompson
> <phil at riverbankcomputing.com>wrote:
>
>> On Fri, 6 Aug 2010 14:57:45 -0400, Eric Frederich
>> <eric.frederich at gmail.com> wrote:
>> > The help only lists the (QVlidator.State, int)... it does not list
the
>> one
>> > that returns a new string.
>> > Does this mean it is not possible?
>> >
>> > I get the same docstring for QValidator.validate when I call
>> > sip.setapi('QString', 1) or sip.setapi('QString', 2)
>> >
>> > This is what I get....
>> >
>> > Help on built-in function validate:
>> >
>> > validate(...)
>> > QValidator.validate(QString, int) -> (QValidator.State, int)
>>
>> The docstring doesn't get changed when you set the API version. It is
>> correct for the default API for the particular version of Python you
are
>> using (v1 for Python2 and v2 for Python3).
>>
>> Phil
>>
More information about the PyQt
mailing list