Skip to content Skip to sidebar Skip to footer

Pyqt - Sqlalchemy Doesn't Accept Qstring

I'm using PyQt and SQLAlchemy and SQLAlchemy doesn't accept QStrings. Is there any way to pass QStrings to it or I have to convert QStrings to Python strings every single time? Tha

Solution 1:

You can change the API to v2 and PyQt will always use regular Python strings instead of QStrings.

Edit

Case 1: Without sip.setapi

import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
c = QtGui.QComboBox()
c.addItems(["one","two"])
print c.currentText(), type(c.currentText())
c.show()
sys.exit(app.exec_())

# Outputs
one <class'PyQt4.QtCore.QString'>

Case 2: With sip.setapi

import sip
sip.setapi("QString",2)

import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
c = QtGui.QComboBox()
c.addItems(["one","two"])
print c.currentText(), type(c.currentText())
c.show()
sys.exit(app.exec_())

# Outputs
one <type'unicode'>

Post a Comment for "Pyqt - Sqlalchemy Doesn't Accept Qstring"