【问题标题】:qgis plugin using python使用python的qgis插件
【发布时间】:2019-05-09 07:46:18
【问题描述】:

我正在尝试使用最新版本的 python 和 qgis 2.18 编写 qgis 插件,但我不断收到以下错误消息:

AttributeError: AutomatisationDEPLOIEMENT instance has no attribute 'utilisat_lineEdit'

这是我的代码,有人能帮帮我吗?

class AutomatisationDEPLOIEMENT:
    """QGIS Plugin Implementation."""

    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgisInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            'AutomatisationDEPLOIEMENT_{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)


        # Declare instance attributes
        self.actions = []
        self.menu = self.tr(u'&Automatisation DEPLOIEMENT')
        # TODO: We are going to let the user set this up in a future iteration
        self.toolbar = self.iface.addToolBar(u'AutomatisationDEPLOIEMENT')
        self.toolbar.setObjectName(u'AutomatisationDEPLOIEMENT')

...剪断...

def loginCheck(self):
    username = self.utilisat_lineEdit.text()
    password = self.pass_lineEdit.text()

    connection = sqlite3.connect("login.db")
    result = connection.execute("SELECT * FROM USERS WHERE USERNAME = ? AND PASSWORD = ?", (username, password))
    if (len(result.fetchall()) > 0):
        print("User Found ! ")
    else:
        print("User Not Found !")
        self.showMessageBox('Warning', 'Invalid Username And Password')
    connection.close()

我正在尝试让 logincheck 功能工作

【问题讨论】:

  • 要使用python 3,您需要使用Qgis 3.x,对于python 2,您可以使用Qgis 2.x,但它现在不支持了。

标签: python plugins qgis


【解决方案1】:

错误信息清楚地显示了你做错了什么: AttributeError: AutomatisationDEPLOIEMENT instance has no attribute 'utilisat_lineEdit'

loginCheck() 的第一行,您尝试访问self.utilisat_lineEdit,但此属性不存在。我猜您正在尝试访问某种 gui 元素,但这在您的课程中不可用。

【讨论】:

  • 是的,但该元素存在于我的 ui 对话框中,但该类无法识别它..如何使该元素在我的类中可用?
  • 调用gui类的实例并从那里访问它?您没有发布任何显示您如何创建/存储 GUI 实例的代码。如果没有更多信息,我无法帮助您。
  • 我使用 qt 设计器创建了接口,并且 ui 文件存储在 qgis 插件文件夹中,旁边是 qgis 在创建插件时生成的 py 文件。我目前正在编辑 py 文件
  • 我认为您缺少一些关于类、实例和引用的基本知识。在您的代码中的某处,您实例化您的 GUI 类并为其分配一些变量。在另一个类中访问此实例的一种方法是在另一个类的构造函数中引用此变量(您的 __init__() 方法),然后保存对该类属性的引用。如果您不知道我在说什么,请阅读一些教程。
猜你喜欢
  • 1970-01-01
  • 2013-09-23
  • 1970-01-01
  • 2016-03-20
  • 2014-05-23
  • 1970-01-01
  • 2016-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多