Question

I am working with python plugins for qgis.I developed the plugin same as rt sql layer and incooperated the same in qgis. Its opening fine when i run qgis exe.But on my ok button ,i have following code to form layer.

# create the layer                      
            uri = self.db.getURI()
            uri.setDataSource("", "(" + query + ")", geomFieldName, "", uniqueFieldName)
            vl = self.iface.addVectorLayer(uri.uri(), newLayerName, self.db.getProviderName())

            QApplication.restoreOverrideCursor()

            if vl and vl.isValid():
                    self.saveQuery()
                    self.accept()

getURI() is defined in another form as follows:

def getURI(self):
            # returns a new QgsDataSourceURI instance

            return qgis.core.QgsDataSourceURI( self.uri.connectionInfo() )

On click of ok button it gives me error saying

 return qgis.core.QgsDataSourceURI( self.uri.connectionInfo() )
AttributeError: 'NoneType' object has no attribute 'connectionInfo'

what should URI contain??

Was it helpful?

Solution

Looks like self.uri in getURI() is not initialized. Have you checked this? Your snippets do not allow to reproduce the problem. Try to post the code where self.uri is filled (and check that this part is actually executed).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top