简体   繁体   中英

PyQT5 QFileDialog issues with Pyinstaller

I'm using PyQt5 with Pycharm and Python 3.7 on Arch Linux (also tried with 3.8). When I run my code from PyCharm or directly from the command line the file dialog opens fine. However, when I build with Pyinstaller I get consistent errors when using them. Code:

def choose_log_location(self):
    self.log_location = QFileDialog.getExistingDirectory(
        self,
        "Choose Log Files Directory",
        "/home",
        options=QFileDialog.ShowDirsOnly)

    if self.log_location != "":
        self.Log_Location.setText(self.log_location)

After building with Pyinstaller, running the built application and clicking the button that fires off this method I get 3 error dialogs pop up:

  1. Error ? URL cannot be listed file:///
  2. Malformed URL
  3. Error ? URL cannot be listed file:///

Then, once the filedialog actually pops up, the main area is blank.

空白 QFileDialog

I also get the following error in the console:

kf5.kio.core: "" qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 7952, resource id: 36398251, major code: 40 (TranslateCoords), minor code: 0

I also get somewhat similar issues using QFileDialog.getOpenFileName() (blank area where files should be - note tested without filter, same result) but a different error in the console:

kf5.kservice.services: KServiceTypeTrader: serviceType "ThumbCreator" not found

获取打开文件名对话框

I had the same problem. It seems that pyinstaller produces this errors with native dialogs. So my solution is to use the DontUseNativeDialog option.

eg

self.log_location = QFileDialog.getExistingDirectory(
        self,
        "Choose Log Files Directory",
        "/home",
        QFileDialog.DontUseNativeDialog)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM