Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create QString in PyQt4?

>>> from PyQt4 import QtCore
>>> str = QtCore.QString('Hello')
AttributeError: 'module' object has no attribute 'QString'

>>> QtCore.QString._init_(self)
AttributeError: 'module' object has no attribute 'QString' 

Yes, I've read QString Class Reference

Why can't I import QString from QtCore, as specified in the docs ?

like image 593
beta-closed Avatar asked Sep 09 '09 17:09

beta-closed


1 Answers

In Python 3, QString is automatically mapped to the native Python string by default:

The QString class is implemented as a mapped type that is automatically converted to and from a Python string. In addition a None is converted to a null QString. However, a null QString is converted to an empty Python string (and not None). (This is because Qt often returns a null QString when it should probably return an empty QString.)

The QChar and QStringRef classes are implemented as mapped types that are automatically converted to and from Python strings.

The QStringList class is implemented as a mapped type that is automatically converted to and from Python lists of strings.

The QLatin1Char, QLatin1String and QStringMatcher classes are not implemented.

http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html

like image 60
Mark Visser Avatar answered Sep 19 '22 08:09

Mark Visser