简体   繁体   English

PYQGIS中的URI问题

[英]URI problem in PYQGIS

I am working with python plugins for qgis .I developed the plugin same as rt sql layer and incooperated the same in qgis . 我正在为qgis使用python插件。我开发了与rt sql层相同的插件,并且在qgis中不使用相同的插件 Its opening fine when i run qgis exe.But on my ok button ,i have following code to form layer . 当我运行qgis exe时,它的打开效果很好。但是在我的确定按钮上,我有以下代码来形成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: getURI()以另一种形式定义如下:

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?? URI应该包含什么?

Looks like self.uri in getURI() is not initialized. 看起来getURI()中的self.uri未初始化。 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). 尝试在填充self.uri的地方发布代码(并检查此部分是否实际执行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM