2

Good day to all, 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
    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.
        pass
  • What is Etiquetas_layoutDialog()? Is it a function or a designer object? – Joseph Feb 14 at 11:29
0

Try moving this line :

name = self.dlg.lineEdit.text()

into the if result: statement

  • Thank you very much for your help, it worked as I wanted. – HRAlva Feb 14 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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