Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Qml Modules not found

Qml Modules not found

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 2 Posters 1.8k Views
  • 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 Offline
    F Offline
    FS93
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      FS93
      wrote on last edited by
      #2

      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'
      
      jsulmJ 1 Reply Last reply
      0
      • F FS93

        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'
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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
        0
        • jsulmJ jsulm

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

          F Offline
          F Offline
          FS93
          wrote on last edited by
          #4

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

          jsulmJ 1 Reply Last reply
          0
          • F FS93

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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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
            0
            • jsulmJ jsulm

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

              F Offline
              F Offline
              FS93
              wrote on last edited by
              #6

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

              jsulmJ 1 Reply Last reply
              0
              • F FS93

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

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

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

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved