I am trying to create my first QGIS 3 plugin, I am using Plugin Builder and Qt Designer, I want to add a variable named name with lineEdit to be able to use the information entered later, however, I receive the following error:

name = self.dlg.lineEdit.text()

AttributeError: 'Etiquetas_layout' object has no attribute 'dlg'

here's my code:

def run(self):
    """Run method that performs all the real work"""
    name = self.dlg.lineEdit.text()
    # Create the dialog with elements (after translation) and keep reference
    # Only create GUI ONCE in callback, so that it will only load when the 
    plugin is started
    if self.first_start == True:
        self.first_start = False
        self.dlg = Etiquetas_layoutDialog()

    # show the dialog
    # 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.

1 Answer 1


Try moving this line :

name = self.dlg.lineEdit.text()

into the if result: statement


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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