QQmlApplicationEngine failed to load component on Python

860 views Asked by At

This problem is similar to QML module not found when using KDE Kirigami , but in this case, setting the QML_IMPORT_PATH env var before running the pyhton file doesn't solve the problem.

I have this simple application:

main.py

#!/usr/bin/python3

from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtQml import QQmlApplicationEngine
from PySide2.QtCore import *

if __name__ == "__main__":
    # Launch application
    app = QApplication()
    engine = QQmlApplicationEngine()
    context = engine.rootContext()
    engine.load("content/ui/main.qml")
    if len(engine.rootObjects()) == 0:
        quit()
    win = engine.rootObjects()[0]
    app.exec_()

main.qml

// Includes relevant modules used by the QML
import QtQuick 2.6
import QtQuick.Controls 2.0 as Controls
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.13 as Kirigami

// Base element, provides basic features needed for all kirigami applications
Kirigami.ApplicationWindow {
    // ID provides unique identifier to reference this element
    id: root

    // Window title
    // i18nc is useful for adding context for translators, also lets strings be changed for different languages
    title: i18nc("@title:window", "Hello World")

    // Initial page to be loaded on app load
    pageStack.initialPage: Kirigami.Page {

        Controls.Label {
            // Center label horizontally and vertically within parent element
            anchors.centerIn: parent
            text: i18n("Hello World!")
        }
    }
}

Before running it, I installed all the required dependencies as explained in https://develop.kde.org/docs/use/kirigami/introduction-getting_started/

sudo apt install build-essential extra-cmake-modules cmake qtbase5-dev qtdeclarative5-dev libqt5svg5-dev qtquickcontrols2-5-dev qml-module-org-kde-kirigami2 kirigami2-dev libkf5i18n-dev gettext libkf5coreaddons-dev qml-module-qtquick-layouts

The kirigami2 module is present at path

/usr/lib/x86_64-linux-gnu/qt5/qml/org/kde/kirigami.2

Btw, when executing the Python file I obtain

QQmlApplicationEngine failed to load component
file:///home/danieleverducci/git/KDE/python/prova-kirigami/content/ui/main.qml:5:1: module "org.kde.kirigami" is not installed

Setting the QML_IMPORT_PATH env var doesn't fix the problem. What am I overlooking?

1

There are 1 answers

1
user19515585 On

using QML2_IMPORT_PATH env instead may fix the problem