简体   繁体   English

Python AttributeError:对象在QGIS插件中没有属性

[英]Python AttributeError : Object has no attribute in QGIS Plugin

I'm trying to create a GUI with QT Designer . 我正在尝试使用QT Designer创建GUI I've converted my .ui designer file to a .py . 我已经将.ui设计器文件转换为.py

Here is my code: 这是我的代码:

from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication 
from PyQt4.QtGui import QAction, QIcon
from qgis.core import *
import resources
from delete_feature_dialog import DeleteFeatureDialog
import os.path

class DeleteFeature:

    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        # Declare instance attributes
        self.actions = []
        self.menu = self.tr(u'&DeleteFeature')
        self.toolbar = self.iface.addToolBar(u'DeleteFeature')
        self.toolbar.setObjectName(u'DeleteFeature')

    def add_action(
        self,
        icon_path,
        text,
        callback,
        enabled_flag=True,
        add_to_menu=True,
        add_to_toolbar=True,
        status_tip=None,
        whats_this=None,
        parent=None):

        # Create the dialog (after translation) and keep reference
        self.dlg = DeleteFeatureDialog()

        ....

        return action

    def initGui(self):  
        icon_path = ':/plugins/DeleteFeature/icon.png'
        self.add_action(
            icon_path,
            text=self.tr(u''),
            callback=self.run,
            parent=self.iface.mainWindow())

    def run(self):
        #this code will populate the combo box with all vector layer
    self.dlg.layerListCombo.clear()
    layers = self.iface.legendInterface().layers()
    layer_list = []
    for layer in layers:
            layerType = layer.type()
            if layerType == QgsMapLayer.VectorLayer:
                layer_list.append(layer.name())
    self.dlg.layerListCombo.addItems(layer_list)
        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()
        # See if OK was pressed
        if result:
            # Do something useful here - delete the line containing pass and
            # substitute with your code.
            selectedLayerIndex = self.dlg.layerlistcombo.currentIndex()
            selectedLayer = layers [selectedLayerIndex]
            .....

Then when I open the plugin, I get the following error: 然后,当我打开插件时,出现以下错误:

'DeleteFeatureDialog' objectObject has no attribute 'layerlistcombo'in QGIS Plugin QGIS插件中的'DeleteFeatureDialog'对象对象没有属性'layerlistcombo'

Any suggestion for this. 任何建议。

Seems that you wrote: 您似乎写了:

selectedLayerIndex = self.dlg.layerlistcombo.currentIndex()

but you should have written: 但您应该写:

selectedLayerIndex = self.dlg.layerListCombo.currentIndex()

Like you did previously in your code (notice the Camel Notation when writing, not just lower-case letters), which is probably causing the No Attribute error you get. 就像您以前在代码中所做的一样(编写时注意驼峰表示法,而不仅是小写字母),这可能会导致您收到“ No Attribute错误。

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

相关问题 Python AttributeError: Object 没有属性 - Python AttributeError: Object has no attribute QGIS插件中“另存为”错误“ X”对象没有属性“ Y” - Save As error 'X' object has no attribute 'Y' in QGIS plugin python错误 - attributeError:'str'对象没有属性 - python error - attributeError: 'str' object has no attribute Python,AttributeError:“ NoneType”对象没有属性“ show” - Python, AttributeError: 'NoneType' object has no attribute 'show' Python:AttributeError:'module'对象没有属性'socketpair' - Python: AttributeError: 'module' object has no attribute 'socketpair' Python AttributeError:对象在Unittest中没有属性 - Python AttributeError: Object has no attribute in Unittest Python:AttributeError:'NoneType'对象没有属性'findNext' - Python: AttributeError: 'NoneType' object has no attribute 'findNext' Python AttributeError:“模块”对象没有属性“获取” - Python AttributeError: 'module' object has no attribute 'get' Python AttributeError: 'NoneType' 对象没有属性 'fileno' - Python AttributeError: 'NoneType' object has no attribute 'fileno' Python AttributeError:“ PostSaveCommand”对象没有属性“ _server” - Python AttributeError: 'PostSaveCommand' object has no attribute '_server'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM