Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While using QGIS and having loaded a non spatial table (from PostGIS), is it possible to add a new row to its table attributes without having to open the attribute table first as in here Is it possible to add a new line in a non-spatial table using Qgis?

Same principle as add a point but with no geometry, just information in a table.

I was able to create a plugin that chooses and starts editing the table but can't get the form window to open so I can fill the fields.

share|improve this question
up vote 2 down vote accepted

I found a way to do it. Here is the code i used

# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import *
from qgis.gui import *

import resources_rc

class SelectFeaturesPlugin:

def __init__(self, iface):
    # Save reference to the QGIS interface
    self.iface = iface

def initGui(self):

    # Create action that will start plugin configuration
    self.action5 = QAction(QIcon(":/plugins/selectfeatures/icon.png"), u"Add Record", self.iface.mainWindow())
    # connect the action to the run method
    QObject.connect(self.action5, SIGNAL("triggered()"), self.addRecord)

    # Add toolbar button and menu item
    self.iface.addPluginToMenu(u"&Add Record", self.action5)

def unload(self):
    # Remove the plugin menu item and icon
    self.iface.removePluginMenu(u"&Add Record",self.action5)

# run method that performs all the real work
def addRecord(self):
    feat = QgsFeature()
    layer = self.iface.activeLayer()
    layer.addFeature( feat )

    from myattrdialog import AttributeDialog
    dlg = AttributeDialog( layer )
    if not dlg.exec_():

    #Populate the feature attrs map usin the values the user inserted in the dialog
    feat.setAttributeMap( dlg.getFeatureAttributeMap() )
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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