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)])
3
  • There is a typo in the first QgsField, which is written QqsField. This probably causes your error.
    – ArMoraer
    Aug 18, 2016 at 9:58
  • You better update to a newer version. QGIS 2.0 is nothing you want to build on today! Aug 18, 2016 at 10:08
  • 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.
    – AnserGIS
    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.

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.