Python Version 3 - Qgis 2.14

1 / what's wrong ?

Lot's of solutions are exposed in differents forum but any work for me. I need to get path to save documents later and i had this error :

TypeError: QFileDialog.getOpenFileName(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 1 has unexpected type 'instance'

Here is my code :

# set event when user click    
# param - function with object argument

# function call by click to open dialog
# param - obj : textEditor object update by directory selection
 def getFolder(self,obj):        
        ddir= QFileDialog.getExistingDirectory(self, 'Select directory')

2 / what is this error ?

If i give no param to QFileDialog.getExistingDirectory() function, windows to explore is open when code is reading. but i just need to open this windows when user click on push button.

If a close window without select directory, i had this error :

dlg.resBtn.clicked.connect(self.getFolder(dlg.txt_res)) TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'


Here is my solution, this work for me: use lambda function to write little function anywhere.





Documentation here :

| improve this answer | |
  • 2
    You could also use the function.partial function which easily allows you to incorporate parameters into a connection (i.e. import using from functools import partial and then use dlg.resBtn.clicked.connect(partial(self.getFolder, dlg.txt_res))). – Joseph Dec 11 '17 at 14:22

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.