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 Import Path issue
Qt 6.11 is out! See what's new in the release blog

QML Import Path issue

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 1 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.
  • L Offline
    L Offline
    LS-KS
    wrote on last edited by
    #1

    Hey
    I Have several Singleton classes and exported them with:

    QML_IMPORT_NAME = "io.qt.textproperties"
    QML_IMPORT_MAJOR_VERSION = 1
    

    This actually never changed and the path itself was generated from Qt Creator.

    In QML I import them like:

    import io.qt.textproperties 1.0
    

    At some point everything was running and I wanted to rename a Python class before I commit.
    Well... after renaming the Python class and renaming also the qml files nothing works.

    QQmlApplicationEngine failed to load component
    file:///Users/.../view/main.qml:5:1: module "io.qt.textproperties" is not installed
    

    I deleted the folder 'io' and hoped to get it recreated by Qt Creator. I also deleted pycache folder even restarted my machine ... but nothing works.
    I also asked copilot to analyze my error but he also says everything is fine.

    I have now commited to this repository although application is not running: link

    I appreciate every hints :-)

    L 1 Reply Last reply
    1
    • L LS-KS

      @LS-KS
      I created a new project as minimal example.
      This should work right?

      main.py:

      # This Python file uses the following encoding: utf-8
      import sys
      from pathlib import Path
      
      from PySide6.QtGui import QGuiApplication
      from PySide6.QtQml import QQmlApplicationEngine
      
      
      if __name__ == "__main__":
          app = QGuiApplication(sys.argv)
          engine = QQmlApplicationEngine()
          qml_file = Path(__file__).resolve().parent / "main.qml"
          engine.load(qml_file)
          if not engine.rootObjects():
              sys.exit(-1)
          sys.exit(app.exec())
      
      

      Controller.py

      # This Python file uses the following encoding: utf-8
      from PySide6 import QtCore
      from PySide6.QtQml import QmlElement, QmlSingleton
      
      QML_IMPORT_NAME = "io.qt.textproperties"
      QML_IMPORT_MAJOR_VERSION = 1
      
      @QmlElement
      @QmlSingleton
      class Controller(QtCore.QObject):
      
          addedOne = QtCore.Signal(int)
      
          def __init__(self, parent = None):
              super().__init__(parent)
      
          @QtCore.Slot(int)
          def addOne(self, value: int):
              self.addedOne.emit(value + 1)
      

      main.qml

      import QtQuick
      import QtQuick.Window
      import QtQuick.Layouts
      
      import io.qt.textproperties 1.0
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Column{
              TextField{
                  id: input
                  text: 0
                  Connections{
                      target: Controller
                      function onAddedOne(result){
                          text = result
                      }
                  }
              }
              Button{
                  text: "add one"
                  onClicked: Controller.addOne(input.text)
              }
          }
      }
      

      Output:

      QQmlApplicationEngine failed to load component
      file:///Users/.../qmlelementtest/main.qml:5:1: module "io.qt.textproperties" is not installed
      

      the folder io.qt.textproperties is only created when I use QtCreators build functionality. With PyCharm / VsCode there will be no directory created which contains qmldir.

      L Offline
      L Offline
      LS-KS
      wrote on last edited by
      #3

      @LS-KS
      stupid me:

      Since main.py doesn't refer to anything from controller.py it was labelled as unused import.
      I didn't think when I hit the shortcut to optimize imports.

      1 Reply Last reply
      0
      • L LS-KS

        Hey
        I Have several Singleton classes and exported them with:

        QML_IMPORT_NAME = "io.qt.textproperties"
        QML_IMPORT_MAJOR_VERSION = 1
        

        This actually never changed and the path itself was generated from Qt Creator.

        In QML I import them like:

        import io.qt.textproperties 1.0
        

        At some point everything was running and I wanted to rename a Python class before I commit.
        Well... after renaming the Python class and renaming also the qml files nothing works.

        QQmlApplicationEngine failed to load component
        file:///Users/.../view/main.qml:5:1: module "io.qt.textproperties" is not installed
        

        I deleted the folder 'io' and hoped to get it recreated by Qt Creator. I also deleted pycache folder even restarted my machine ... but nothing works.
        I also asked copilot to analyze my error but he also says everything is fine.

        I have now commited to this repository although application is not running: link

        I appreciate every hints :-)

        L Offline
        L Offline
        LS-KS
        wrote on last edited by
        #2

        @LS-KS
        I created a new project as minimal example.
        This should work right?

        main.py:

        # This Python file uses the following encoding: utf-8
        import sys
        from pathlib import Path
        
        from PySide6.QtGui import QGuiApplication
        from PySide6.QtQml import QQmlApplicationEngine
        
        
        if __name__ == "__main__":
            app = QGuiApplication(sys.argv)
            engine = QQmlApplicationEngine()
            qml_file = Path(__file__).resolve().parent / "main.qml"
            engine.load(qml_file)
            if not engine.rootObjects():
                sys.exit(-1)
            sys.exit(app.exec())
        
        

        Controller.py

        # This Python file uses the following encoding: utf-8
        from PySide6 import QtCore
        from PySide6.QtQml import QmlElement, QmlSingleton
        
        QML_IMPORT_NAME = "io.qt.textproperties"
        QML_IMPORT_MAJOR_VERSION = 1
        
        @QmlElement
        @QmlSingleton
        class Controller(QtCore.QObject):
        
            addedOne = QtCore.Signal(int)
        
            def __init__(self, parent = None):
                super().__init__(parent)
        
            @QtCore.Slot(int)
            def addOne(self, value: int):
                self.addedOne.emit(value + 1)
        

        main.qml

        import QtQuick
        import QtQuick.Window
        import QtQuick.Layouts
        
        import io.qt.textproperties 1.0
        
        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            Column{
                TextField{
                    id: input
                    text: 0
                    Connections{
                        target: Controller
                        function onAddedOne(result){
                            text = result
                        }
                    }
                }
                Button{
                    text: "add one"
                    onClicked: Controller.addOne(input.text)
                }
            }
        }
        

        Output:

        QQmlApplicationEngine failed to load component
        file:///Users/.../qmlelementtest/main.qml:5:1: module "io.qt.textproperties" is not installed
        

        the folder io.qt.textproperties is only created when I use QtCreators build functionality. With PyCharm / VsCode there will be no directory created which contains qmldir.

        L 1 Reply Last reply
        0
        • L LS-KS

          @LS-KS
          I created a new project as minimal example.
          This should work right?

          main.py:

          # This Python file uses the following encoding: utf-8
          import sys
          from pathlib import Path
          
          from PySide6.QtGui import QGuiApplication
          from PySide6.QtQml import QQmlApplicationEngine
          
          
          if __name__ == "__main__":
              app = QGuiApplication(sys.argv)
              engine = QQmlApplicationEngine()
              qml_file = Path(__file__).resolve().parent / "main.qml"
              engine.load(qml_file)
              if not engine.rootObjects():
                  sys.exit(-1)
              sys.exit(app.exec())
          
          

          Controller.py

          # This Python file uses the following encoding: utf-8
          from PySide6 import QtCore
          from PySide6.QtQml import QmlElement, QmlSingleton
          
          QML_IMPORT_NAME = "io.qt.textproperties"
          QML_IMPORT_MAJOR_VERSION = 1
          
          @QmlElement
          @QmlSingleton
          class Controller(QtCore.QObject):
          
              addedOne = QtCore.Signal(int)
          
              def __init__(self, parent = None):
                  super().__init__(parent)
          
              @QtCore.Slot(int)
              def addOne(self, value: int):
                  self.addedOne.emit(value + 1)
          

          main.qml

          import QtQuick
          import QtQuick.Window
          import QtQuick.Layouts
          
          import io.qt.textproperties 1.0
          
          Window {
              width: 640
              height: 480
              visible: true
              title: qsTr("Hello World")
          
              Column{
                  TextField{
                      id: input
                      text: 0
                      Connections{
                          target: Controller
                          function onAddedOne(result){
                              text = result
                          }
                      }
                  }
                  Button{
                      text: "add one"
                      onClicked: Controller.addOne(input.text)
                  }
              }
          }
          

          Output:

          QQmlApplicationEngine failed to load component
          file:///Users/.../qmlelementtest/main.qml:5:1: module "io.qt.textproperties" is not installed
          

          the folder io.qt.textproperties is only created when I use QtCreators build functionality. With PyCharm / VsCode there will be no directory created which contains qmldir.

          L Offline
          L Offline
          LS-KS
          wrote on last edited by
          #3

          @LS-KS
          stupid me:

          Since main.py doesn't refer to anything from controller.py it was labelled as unused import.
          I didn't think when I hit the shortcut to optimize imports.

          1 Reply Last reply
          0
          • L LS-KS has marked this topic as solved on

          • Login

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