[SOLVED] .getSaveFileName doesn't work in Qgis



  • Hi guys, I'm beginner in Qt and I got stuck on probably very simple problem. So, here is my code:

     def select_output_file(self):
    		filename = QtGui.QFileDialog.getSaveFileName(self, "Select output file ","", '*.txt')
    		self.dlg.lineEdit.setText(filename)
    		
    		self.dlg.lineEdit.clear()
    		self.dlg.pushButton.clicked.connect(self.select_output_file)
    

    The problem is, that I don't know the error- everything is pretending to be ok, but the push button doesn't work. I click on it and almost nothing happens- it is active, but there is no action. I saw similar problem with solution on stackexchanege, but nothing works in my case. I imported needed stuff from QtGui library. And I have no idea what's going on.



  • I have no experience in Qgis. But you code snippet seems like a python code. According to your code your connections is never set since you are connectig to the slot in slot function. (the last line). You have to make your connections before signals are fired. Otherwise they wont be catched in slot functins.

    I suggest move you connect line into the constructor.



  • @asanka424 Thanks a lot! Your suggestion works. After moving the connect line into the constructor, I also needed to change this:

    filename = QFileDialog.getSaveFileName(self, "Select output file ","", '*.txt')
    

    to this:

    filename = QFileDialog.getSaveFileName(None, "Select output file ","", '*.txt')
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.