Problem in QString API version 2, is it possible to use QString version 1 in pythonxy?

122 views
Skip to first unread message

Feng Zhu

unread,
Oct 7, 2015, 1:15:49 PM10/7/15
to python(x,y)
Hello All,

I got a problem of using QString api version 2. 

Basically, I have a software which was developed using python 2.5.  I am now trying to the code work with python 2.7. I chose the pythonxy 2.7.9 package since it has almost all libraries I need. 

First, I found I need to setup set QT_API=pyqt in system environment first. Otherwise it tries to use Pyside which is not working for my code. I don't know why there are to Qt inside. 

Then, the real problem is my software was developed in python 2.5 which used QString version 1. 

So in QString API version 1, I can do something like.

from PyQt4.QtCore import QString

However, in pythonxy 2.7.9, it force to set api to version 2 at low level code __init__.py in qt. So I got the following error:

    ValueError: API 'QString' has already been set to version 1

So I manually add the follow code at very beginning of my software to setup api to version 2

        import sip
        sip.setapi('QString', 2)
        sip.setapi('QVariant', 2)


However, I then cannot import QString from QtCore. 

I read some posts from other website. It says the QString is eliminated from API version 2. I should use python string as replacement. The problem is I have thousands of lines have QString. It would take ages to change it to python string. And I also don't know if my code will work after change all QString to python string. 

I also tried to change the API version to 1 at version low level code __init__.py in qt.

    def prepare_pyqt4():
        # Set PySide compatible APIs.
        import sip
        sip.setapi('QString', 1)
        sip.setapi('QVariant', 1)

I then got hundreds strange error when I launch my software, for example:

****) FlightPad: Unhandled exception
Traceback (most recent call last):
  File "C:\python27\lib\site-packages\pyface\ui\qt4\workbench\split_tab_widget.py", line 310, in _focus_changed
    ntw, ntidx = self._tab_widget_of(new)
  File "C:\python27\lib\site-packages\pyface\ui\qt4\workbench\split_tab_widget.py", line 331, in _tab_widget_of
    for tw in self.findChildren(_TabWidget, None):
TypeError: arguments did not match any overloaded call:
  QObject.findChildren(type, QString name=QString()): argument 2 has unexpected type 'NoneType'
  QObject.findChildren(tuple, QString name=QString()): argument 1 has unexpected type 'PyQt4.QtCore.pyqtWrapperType'
  QObject.findChildren(type, QRegExp): argument 2 has unexpected type 'NoneType'
  QObject.findChildren(tuple, QRegExp): argument 1 has unexpected type 'PyQt4.QtCore.pyqtWrapperType'
An unexpected error has occurred:
 arguments did not match any overloaded call:
  QObject.findChildren(type, QString name=QString()): argument 2 has unexpected type 'NoneType'
  QObject.findChildren(tuple, QString name=QString()): argument 1 has unexpected type 'PyQt4.QtCore.pyqtWrapperType'
  QObject.findChildren(type, QRegExp): argument 2 has unexpected type 'NoneType'
  QObject.findChildren(tuple, QRegExp): argument 1 has unexpected type 'PyQt4.QtCore.pyqtWrapperType'(<type 'exceptions.TypeError'>)

It looks like pythonxy at low level doesn't like QString API version to be set 1. 

Could anyone please advise me what I should do to fit my code? Should I replace python string of QString in my code thousands lines? Or if there is any official way to keep use QString version 1 in pythonxy?

Thanks very much! Looking forward to your reply.

Best Regards,







Reply all
Reply to author
Forward
0 new messages