Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Qml Modules not found

    Qt for Python
    2
    7
    651
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      FS93 last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • F
        FS93 last edited by

        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'
        
        jsulm 1 Reply Last reply Reply Quote 0
        • jsulm
          jsulm Lifetime Qt Champion @FS93 last edited by

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          F 1 Reply Last reply Reply Quote 0
          • F
            FS93 @jsulm last edited by

            @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).

            jsulm 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @FS93 last edited by

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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              F 1 Reply Last reply Reply Quote 0
              • F
                FS93 @jsulm last edited by

                @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?

                jsulm 1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @FS93 last edited by

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

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post