I am new to Plugin Builder and creating my first plugin called
NearestNeighbour. The below is GUI of my plugin made using
I read in this link that it is important to rename Dialog Box, Toolbox because it will be used in our code.
Label are kept as it is with object name
label_2 respectively. The
LineEdit objectName for Upload Node Layer is called
lineEdit. On a similar basis the second
LineEdit objectName for Upload Building Layer is called
lineEdit_2. In a similar way the
Push Buttonfor Upload Node Layer is called
pushButton and the second
Tool Button for Upload Building Layer is called
pushButton_2. With reference to the link mentioned above, I have done the Following change in my
1) Add the below line where all imports are done
from qgis.core import QgsProject
QtWidget to the list of imports at the top of the file.
from PyQt5.QtWidgets import QAction, QFileDialog
3) Add a new method called Upload_Point_Layer with the following code just above
def Upload_Point_Layer(self): filename, _filter = QFileDialog.getSaveFileName( self.dlg, "Select output file ","", '*.shp') self.dlg.lineEdit.setText(filename)
4) In the run method, added the following line in the block where the dialog is initialized.(This code will connect the Upload_Point_Layer method to the clicked signal of the push button widget)
I want to know what I am doing wrong or are there any other files that also need to be edited ? I am using
32 Bit Windows operating System and using
But after saving the changes, when I tried to reload the plugin I have got the below error
Couldn't load plugin 'Nearest_Neighbour' due to an error when calling its classFactory() method AttributeError: 'NearestNeighbour' object has no attribute 'dlg' Traceback (most recent call last): File "C:/OSGeo4W/apps/qgis/./python\qgis\utils.py", line 335, in startPlugin plugins[packageName] = package.classFactory(iface) File "C:/Users/Prachi/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Nearest_Neighbour\__init__.py", line 36, in classFactory return NearestNeighbour(iface) File "C:/Users/Prachi/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Nearest_Neighbour\Nearest_Neighbour.py", line 73, in __init__ self.dlg.lineEdit.clear() AttributeError: 'NearestNeighbour' object has no attribute 'dlg'