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. How to deploy QML with PyInstaller?
Qt 6.11 is out! See what's new in the release blog

How to deploy QML with PyInstaller?

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2qt for python
2 Posts 1 Posters 1.5k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Curtwagner1984
    wrote on last edited by
    #1

    Hello,

    I have a small python QML app that I'm trying to deploy to an exe file. I found this SO answer to this issue.

    I wanted to use option #3. Specifically add my qml files to the QT Resource system using a QRC file and then compile it and import it into python.

    The answer states that if your folder stracture is

    project
    │   main.py
    │   main.qml    
    

    You should create a qrc file like so:

    qml.qrc:

    <RCC>
      <qresource>
          <file>main.qml</file>
      </qresource>
    </RCC>
    

    Then convert the qml to py like this: pyside2-rcc qml.qrc -o qml_rc.py

    And then you're good to go.

    The issue I'm having is, that I have multiple QML components, like so:

    project
    │   QML
    |    |-main.qml
    |    |-MainComponent.qml
    |    |-RowComponent.qml
    │   main.py
    

    I've made a qrc file like the answer suggested:

    <RCC>
      <qresource>
          <file>QML/main.qml</file>
          <file>QML/MainComponent.qml</file>
          <file>QML/RowComponent.qml</file>
      </qresource>
    </RCC>
    

    And then I followed the rest of the instructions.

    When I give the uri of ":/QML/main.qml" to the engine like so:

     engine = QQmlApplicationEngine()
     engine.load(":/QML/main.qml")
    

    It says it fails to load a component named MainComponent

    Warning: file::/QML/main.qml:51:5: MainComponent is not a type (file::/QML/main.qml:51, file::/QML/main.qml)
    

    Because all my QML files are in the same folder, I reference them just by calling the type name. However this seems to be insufficient when using this method.

    I think I'm missing an import statement in my main.qml that would tell the engine where to file MainComponent. But I don't know what import statement it should be.

    Could anyone help me out?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Curtwagner1984
      wrote on last edited by
      #2

      OK, after more searching I found this answer form the same helpful author.

      He says that when the qml files aren't in the root folder you should add
      import "qrc:/QML in the main file so it could see other components in the qrc file. (This path is specfic to my case because my qml files are in ./qml folder.)

      On thing to note that might seem obvious but I spent quite a few tries to figure it out is that you must compile the qrc file
      to py after every change you make to the qml files.

      Meaning running pyside2-rcc qml.qrc -o qml_rc.py. Otherwise the imports won't update, and you'll be stuck trying to figure out why the changes you're making don't affect anything.

      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