Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#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 trapanator, 14 years ago

note: I tried to remove QString(), same result.

comment:2 by trapanator, 14 years ago

err... I mispelled the title: s/addFeature/addAttribute/ :-(

comment:3 by jef, 14 years ago

Summary: addFeature() doesn't work in QGISaddAttribute() doesn't work

comment:4 by jef, 14 years ago

Owner: borysiasty removed

comment:5 by wonder, 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 trapanator, 14 years ago

Resolution: worksforme
Status: newclosed

Ok. Using QVariant fixes the problem. Thank you to all.

comment:7 by trapanator, 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.