0

I'm trying to add a FileDialog in QML, my environment:

  • Python 3.10.8
  • PyQt6
  • Arch Linux
  • qt6-base, qt6-declarative packages installed

Code:

main.qml

import QtQuick 
import QtQuick.Window 
import QtQuick.Controls 
import QtQuick.Dialogs

Window {

    Rectangle {
        id: mainRect
        anchors.fill: parent

        Button {
            text: qsTr("Open File")
            onClicked: fileDialog.open()
        }
    }


    FileDialog {
        id: fileDialog

    }

}

main.py

import os
import sys
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine


def main():
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()

    engine.load(os.fspath(Path(__file__).resolve().parent / "qml/main.qml"))

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec())

if __name__ == "__main__":
    main()

When I try to run it produces this error:

file:///main.qml:20:5: QML FileDialog: Failed to load non-native FileDialog implementation:
qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/FileDialog.qml:4 module "Qt.labs.folderlistmodel" is
not installed

Segmentation fault (core dumped)

I've tried searching the package repo and pypi to find if there's an extra package that contains this folderlistmodel but I couldn't find any.

  • It should be part of qt6-declarative (see https://archlinux.org/packages/extra/x86_64/qt6-declarative/files/). What Qt version do you have? – musicamante Dec 05 '22 at 19:06
  • Thanks @musicamante I've qt6-declarative 6.4.1-1 installed which is the latest according to the package page you provided, also qt6-base has the same version. – Arsany Samuel Dec 05 '22 at 22:47
  • Have you tried qml6-module-qt-labs-folderlistmodel or libqt6labsfolderlistmodel6? – Mitch Dec 06 '22 at 00:22
  • @Mitch I've searched for any package with folderlistmodel in its name in the main Arch Linux repo and AUR but I found nothing, it should be included in qt6-declarative which I tried to reinstall but no luck. – Arsany Samuel Dec 06 '22 at 09:07

2 Answers2

0

I've tried FileDialog on Windows and it works fine, it seems like an Arch Linux packaging issue but I'm not sure where to report. I've used a workaround mentioned in this answer using tkinter and it works fine on both OSs.

0

pyside6 must be installed:

export QML2_IMPORT_PATH=/usr/local/lib/python3.8/site-packages/PySide6/Qt/qml

In docker:

ENV QML2_IMPORT_PATH=/usr/local/lib/python3.8/site-packages/PySide6/Qt/qml
NelDav
  • 785
  • 2
  • 11
  • 30
  • Currently it looks like export QML2_IMPORT_PATH... would install pyside6. Better state that this command should be executed after doing that. Also state, why the command must be executed. – NelDav Jul 26 '23 at 11:40