error when calling QtGui.QFileDialog.getExistingDirectory

♀尐吖头ヾ 提交于 2019-12-13 04:46:14

问题


In a pyqt code, I am trying to promote a dialog to the user and let the user to select a folder. It seems QtGui.QFileDialog.getExistingDirectory method should be able to do that. The problem is there are a couple of error messages after the code is ran.

D_Lib: debug printing for files [.*] and level [100] is turned on
D_Lib: debug printing for files [.*] and level [200] is turned on
D_Lib: debug printing for files [.*] and level [300] is turned on
11148:vf_shex.cpp(84): INFO: DllCanUnloadNow returned S_OK.

What has happened?

A example would look like this:

import sys
from PyQt4 import QtGui, QtCore

class FilePicker(QtGui.QWidget):
    """
    An example file picker application
    """

    def __init__(self):
        # create GUI
        QtGui.QMainWindow.__init__(self)
        self.setWindowTitle('File picker')
        # Set the window dimensions
        self.resize(300,75)

        # vertical layout for widgets
        self.vbox = QtGui.QVBoxLayout()
        self.setLayout(self.vbox)

        # Create a label which displays the path to our chosen file
        self.lbl = QtGui.QLabel('No file selected')
        self.vbox.addWidget(self.lbl)

        # Create a push button labelled 'choose' and add it to our layout
        btn = QtGui.QPushButton('Choose file', self)
        self.vbox.addWidget(btn)

        # Connect the clicked signal to the get_fname handler
        self.connect(btn, QtCore.SIGNAL('clicked()'), self.get_fname)

    def get_fname(self):
        """
        Handler called when 'choose file' is clicked
        """
        # When you call getOpenFileName, a file picker dialog is created
        # and if the user selects a file, it's path is returned, and if not
        # (ie, the user cancels the operation) None is returned
        try:
            fname = QtGui.QFileDialog.getOpenFileName(self, 'Select file')
        except:
            pass
        if fname:
            self.lbl.setText(fname)
        else:
            self.lbl.setText('No file selected')


# If the program is run directly or passed as an argument to the python
# interpreter then create a FilePicker instance and show it
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    gui = FilePicker()
    gui.show()
    app.exec_()

回答1:


I cannot reproduce this on my system.

A quick google search returns this result which indicates that the message is caused by a "Viewfinity" product being installed on the system, and is not an issue with PyQt. It seems that this product has modified the native system file dialog. You could avoid it by either uninstalling the product, or asking Qt to not use the native file dialog with the Qt.DontUseNativeDialog option when you create the dialog.



来源:https://stackoverflow.com/questions/32056783/error-when-calling-qtgui-qfiledialog-getexistingdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!