Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qml Modules not found



  • I am working on a project involving Qt Quick and Python on a Raspberry Pi 4. I installed Qt 5.15.2 following these steps, the installation folder is in /opt/. However, when I try to run my main.py script, I get errors in my qml files at import, as some modules are not found properly. How can I tell my Python and QML to look for the modules in the correct folders (i.e. the newly installed Qt5.15.2 in the /opt/ folder)? I tried with setting QML2_IMPORT_PATH but this did not help (or I did it uncorrectly). It looks like my script is looking for the qml modules in the wrong path (which I installed previously with 'sudo apt-get install'), or am I missing something else?



  • More specifically, this is my code:

    from PySide2.QtWidgets import QApplication
    from PySide2.QtQml import QQmlApplicationEngine
    import os
    
    import sys 
    
    app = QApplication([])
    
    engine = QQmlApplicationEngine()
    
    os.environ['QT_DEBUG_PLUGINS']= '1'
    
    engine.addImportPath('/opt/Qt/5.15.2/qml')
    engine.addPluginPath('/opt/Qt/5.15.2/plugins')
    
    print(engine.pluginPathList())
    print(engine.importPathList())
    
    #load qml file
    engine.load("view.qml")
    
    if not engine.rootObjects():
       sys.exit(-1)
    sys.exit(app.exec_())
    

    and a simple qml file:

    import QtQuick 2.15
    
    Rectangle {
        width: 200
        height: 200
        color: "green"
    
        Text {
            text: "Hello World"
            anchors.centerIn: parent
        }
    }
    

    This is the output of the two print statements:

    ['/opt/Qt/5.15.2/plugins', '.']
    ['/opt/Qt/5.15.2/qml', '/usr/bin', 'qrc:/qt-project.org/imports', '/usr/lib/arm-linux-gnueabihf/qt5/qml']
    

    And this is the error thrown:

    QQmlApplicationEngine failed to load component
    file:///home/pi/example_pyside/view.qml:1 plugin cannot be loaded for module "QtQuick": Failed to extract plugin meta data from '/opt/Qt/5.15.2/qml/QtQuick.2/libqtquick2plugin.so'
    

  • Lifetime Qt Champion

    @FS93 said in Qml Modules not found:

    engine.addImportPath('/opt/Qt/5.15.2/qml')

    Why do you set these paths? Your PySide installation should know where to find its stuff.



  • @jsulm said in Qml Modules not found:

    @FS93 said in Qml Modules not found:

    engine.addImportPath('/opt/Qt/5.15.2/qml')

    Why do you set these paths? Your PySide installation should know where to find its stuff.

    Because I manually installed Qt5.15.2 following these steps https://www.tal.org/tutorials/building-qt-515-raspberry-pi . Pyside would look for the standard installation folder which I get when I install Qt with the apt-get command (but with this method I get an older version of Qt).


  • Lifetime Qt Champion

    @FS93 Then I guess your PiSide was build with a different Qt version and is not compatible with Qt you built.



  • @jsulm said in Qml Modules not found:

    @FS93 Then I guess your PiSide was build with a different Qt version and is not compatible with Qt you built.

    I understand. So, since I am on a Raspberry Pi and on a RPi I cannot install the correct PySide2 version through pip, how do you suggest I could proceed in order to install the right Pyside version?

    Or is there no way to make it work and I should just give up on using Qt5.15 on my RPi with Pyside? The thing is, I built my app on a desktop where I could use Qt5.15, so in this latter case I would have to "downgrade" all the imported qml modules in order to make it work on an older version for the RPi. Correct?


  • Lifetime Qt Champion

    @FS93 You could build PiSide by yourself using your Qt build


Log in to reply