#2378 closed bug (worksforme)
addAttribute() doesn't work
Reported by: | trapanator | Owned by: | |
---|---|---|---|
Priority: | major: does not work as expected | Milestone: | Version 1.5.0 |
Component: | Python plugins and bindings | Version: | Trunk |
Keywords: | Cc: | ||
Must Fix for Release: | Yes | Platform: | Debian |
Platform Version: | Awaiting user input: | no |
Description
Hi, I wrote a python plugin that does a:
feat = QgsFeature() [...] x = 0 y = "hello" feat.addAttribute (x, QString(y))
In Windows it works well, but in Ubuntu Jaunty (and QGIS 1.4.0) it gives this error:
TypeError: argument 2 of QgsFeature.addAttribute() has an invalid type
Change History (7)
comment:1 by , 14 years ago
comment:3 by , 14 years ago
Summary: | addFeature() doesn't work in QGIS → addAttribute() doesn't work |
---|
comment:4 by , 14 years ago
Owner: | removed |
---|
comment:5 by , 14 years ago
addAttribute() method expects QVariant instance, not QString. So this should work:
feat.addAttribute (x, QVariant(y))
The difference in behaviour is probably due different SIP/PyQt4 versions on your systems: one might support automatic conversion from QString to QVariant, while the other doesn't.
comment:6 by , 14 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Ok. Using QVariant fixes the problem. Thank you to all.
comment:7 by , 14 years ago
Ubuntu Karmic has QT 4.5.2, while Jaunty 4.5.0.
With Karmic QVariant is optional, while Jaunty is mandatory.
Note:
See TracTickets
for help on using tickets.
note: I tried to remove QString(), same result.