Discussion:
name 'QString' is not defined
Znarf1965
2014-04-04 07:49:23 UTC
Permalink
Hi Everybody,

I can't use QString class inside QGis Python Console or inside QGis Python
plugins.
If I use inside a stand alone pyw application, I have no problem (please
note that I run pyw from Eclipse).

Here you are what I do and get inside QGis Python Console:


Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on
WIN-J13S01PK4M5
## Type help(iface) for more info and list of methods.
from PyQt4.QtCore import *
action = QString()

Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'QString' is not defined


Are there anybody that can suggest me something?...

Best regards

Francesco



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/name-QString-is-not-defined-tp5133044.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
Denis Rouzaud
2014-04-04 07:53:34 UTC
Permalink
Hi Francesco,

I might be not using the right terms, but since the new SIP API (version
2), you're not supposed to use Qt types but the standard python types.
So you're suppose to use str() instead of QString.

You my find more details here
https://hub.qgis.org/wiki/17/Python_plugin_API_changes_from_18_to_20

Cheers,

Denis
Post by Znarf1965
Hi Everybody,
I can't use QString class inside QGis Python Console or inside QGis Python
plugins.
If I use inside a stand alone pyw application, I have no problem (please
note that I run pyw from Eclipse).
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on
WIN-J13S01PK4M5
## Type help(iface) for more info and list of methods.
from PyQt4.QtCore import *
action = QString()
File "<input>", line 1, in <module>
NameError: name 'QString' is not defined
Are there anybody that can suggest me something?...
Best regards
Francesco
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/name-QString-is-not-defined-tp5133044.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Martin Dobias
2014-04-04 08:12:52 UTC
Permalink
Post by Denis Rouzaud
Hi Francesco,
I might be not using the right terms, but since the new SIP API (version 2),
you're not supposed to use Qt types but the standard python types.
So you're suppose to use str() instead of QString.
To be precise, use 'unicode' type instead of QString, the 'str' type
is equivalent of QByteArray. Using 'str' for text leads to problems
with non-ascii characters.

(In Python3, the 'unicode' type has become 'str' and 'str' type has
become 'bytes' - but QGIS still uses Python2)

Regards
Martin

Loading...