0

Im writing a stand alone app in Python using QGIS 2.01 on Ubuntu via Eclipse bindings.

I've written code which successfully adds features to a new in memory layer and displays, but now I want to add attributes. The following code is giving an error : "Undefined Variable: QgsField" error despight importing both "qgis.core *" and specifically QgsField.

import os
import os.path
from PyQt4.QtGui import *
from PyQt4.QtCore import * 
from qgis.gui import *
from qgis.core import * 
from PyQt4.QtGui import QAction, QMainWindow
from PyQt4.QtCore import SIGNAL, Qt
from qgis.core import QgsVectorLayer, QgsField, QgsMapLayerRegistry 
from PyQt4.QtCore import QVariant 
Graphiclayers = QgsMapLayerRegistry.instance().mapLayers().values() 
 GraphLyr = Graphiclayers[0]
 pr = GraphLyr.dataProvider() 
 # add fields
 pr.startediting()
 pr.addAttributes([QqsField('Colour', QVariant.Int),
 QgsField('QTriad', QVariant.Int),
 QgsField('QBox', QVariant.Int)])
asked Aug 18, 2016 at 9:56
3
  • There is a typo in the first QgsField, which is written QqsField. This probably causes your error. Commented Aug 18, 2016 at 9:58
  • You better update to a newer version. QGIS 2.0 is nothing you want to build on today! Commented Aug 18, 2016 at 10:08
  • 1
    yeah.. its a personal project in my spare time so QGIS is progressing faster than my code.. hopefully it will upgrade without too many issues when complete, but one issue at a time. Commented Aug 18, 2016 at 10:16

1 Answer 1

2

(Ok then!)

There is a typo in the first QgsField, which is written QqsField. This probably causes your error.

answered Aug 18, 2016 at 10:02
1
  • 1
    Just one of those cases where you stare too long at a problem! thanks for the swift response, saved me allot more staring... Commented Aug 18, 2016 at 10:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.