Problem to use QString API version 1 or 2.

53 views
Skip to first unread message

Feng Zhu

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

Hello,

 

I got some problem to use QString API version 2.

 

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

 

The first thing I realise is that I need to set QT_API=pyqt in system environment. Otherwise, it will pythonxy will try to use PySide Qt, which is not working with my code.

 

Then, the real problem is my code was developed with python 2.5, so it used QString version 1.

 

So in QString API version 1, I can do:

 

from PyQt4.QtCore import QString

 

However, I found that pythonxy 2.7.9 forced to set QString API version to 2, at low level code __init__.py in qt.

 

So I have to add the following code at very beginning of my code:

 

import sip

sip.setapi('QString'2)

sip.setapi('QVariant'2)

 

However, after I set it to API 2. I cannot import QString from QtCore anymore.

 

I read some posts from other website. It says QString is eliminated from API version 2. It suggests to use python string replace all QString. However, I have thousands of lines have QString. It will take long time to replace. And I also don’t know if python string will work.

 

I also tried to force set QString API to 1 at low level code, __init__.py in qt by:

 

 

def prepare_pyqt4():

    Set PySide compatible APIs.

    import sip

    sip.setapi('QString'1)

    sip.setapi('QVariant'1)

 

Then, I will get hundreds of strange erros, 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'

QWidget::create: Failed to create window ()

*) pyface.workbench.workbench: window <psi.workbench.workbench_window.WorkbenchWindow object at 0x05D56630> activated

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'>)

****) 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'

QWidget::create: Failed to create window ()

 

Could any one advise me what I should do to make pythonxy works. Shall I change thousands lines to replace python string to QString. Or if there is any officially way to keep using QString version 1 in python xy?

 

Thanks very much for the help.

 

Best Regards,

Reply all
Reply to author
Forward
0 new messages