[PyQt] modeltest.py for PyQt5?
me at the-compiler.org
Wed Aug 13 15:40:07 BST 2014
* Nenad Ognjanovic <bgr.gyk at gmail.com> [2014-08-13 16:04:46 +0200]:
> I've noticed that modeltest.py is no longer present in PyQt source.
> Since I've started porting the old one to PyQt5, I'm interested in knowing
> if there was any reason for excluding it in the first place, other than not
> being compatible anymore?
> Also, a good question at this point would be: does a PyQt5 version of
> modeltest.py already exist?
> The most recent one I've managed to find is the PyQt4 version from tortoisehg
> repository. I've started porting this version to PyQt5, but I've quickly hit
> a bump. I'd like to know if anyone here is interested in helping to get this
> ported, since I'm not familiar with the internals of Qt/PyQt/sip.
Oh, awesome! I wasn't aware of that, and started porting it from C++
to Python myself, but didn't get very far.
> The source can be found at: https://github.com/bgr/PyQt5_modeltest
> Not much was changed so far.
> The first problem I've encountered happens at this point:
> with the following error:
> AttributeError: 'NoneType' object has no attribute 'isValid'
> I've identified that this happens due to sip.cast at line #44, which causes
> the returned QVariant to be converted into None. When the line #238 is
> changed to access the original self._model directly, the QVariant is returned
PyQt5 uses native Python types instead of QVariant - see
You can probably either do sip.enableautoconversion(QVariant, False)
or handle the native types instead.
AFAIK, it returns None when a function returns an invalid QVariant,
so you probably simply want to change "not qvar.isValid()" to
"qvar is None", and change all "variant.isValid()" to
"variant is not None". Same also in line 426, but keep .isValid
everywhere when a QModelIndex is checked.
Not sure why you'd get an actual QVariant without the sip.cast though.
I'd be happy to help where I can if you run into other issues -
Mail/XMPP is in the signature, or "The-Compiler" on Freenode.
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 819 bytes
Desc: not available
More information about the PyQt