1

I am wanting to use the Felgo tool kit to extend Qt's qml types when writing a python application but keep running into issues and haven't had much luck getting it up and running. I am curious if others have been able to successfully use the Felgo library when writing qml in a python app. If so, how did you do it?

Here is what I have done thus far:

  1. Downloaded Felgo and have it working inside QtCreator (no python used here)

  2. Created a venv, pip installed Pyside2 into the venv.

  3. Created a very simple qml file that uses Felgo components and a python file to run it.

//main.qml

import Felgo 3.0
import QtQuick 2.0

App {
    id: app
    AppText {
        text: "Hello World"
        anchors.centerIn: parent
    }
}
#main.py

import sys
import os

from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine


if __name__ == "__main__":
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())
  1. Since Felgo is not shipped with PySide2, I copy all the Felgo related components that were installed from the QT folder and paste them into '...\venv\Lib\site-packages\PySide2\qml' to join the rest of the standard qml components. These are the folders and file I grabbed
  • C:\Qt\Qt\5.12.8\mingw73_64\qml\Felgo
  • C:\Qt\Qt\5.12.8\mingw73_64\qml\VPlay
  • C:\Qt\Qt\5.12.8\mingw73_64\qml\VPlayApps
  • C:\Qt\Qt\5.12.8\mingw73_64\qml\VPlayPlugins
  • C:\Qt\Qt\5.12.8\mingw73_64\qml\builtins.qmltypes
  1. When I try to run it, I get this error
QQmlApplicationEngine failed to load component
file:///C:/Users/jblos/PycharmProjects/Felgo/TestProject/main.qml:3:1: module "Felgo" is not installed

Am I forgetting something?

Edit 1:

After matching the Qt's version Felgo was built against (for me it was 5.13.2) with the pyside2 version (pip install pyside2==5.13.2), this solved a couple problems that I was seeing. I was no longer was seeing "Felgo" is not installed. And it also resolved some issues with there being cyclic qml dependency issues present.

Now the app will technically run and "work" but none of the theming is present. Simple buttons or navigation bars do not look anything like the live preview shown. python vs Felgo Live Preview

Looking at the Felgo main.cpp sample applications, they are using a FelgoApplication class that might be doing some more setup or initialization that might not be happening?

// main.cpp from sample application

#include <QApplication>
#include <FelgoApplication>

#include <QQmlApplicationEngine>

// uncomment this line to add the Live Client Module and use live reloading with your custom C++ code
//#include <FelgoLiveClient>

int main(int argc, char *argv[])
{

    QApplication app(argc, argv);

    FelgoApplication felgo;

    // Use platform-specific fonts instead of Felgo's default font
    felgo.setPreservePlatformFonts(true);

    QQmlApplicationEngine engine;
    felgo.initialize(&engine);

    // Set an optional license key from project file
    // This does not work if using Felgo Live, only for Felgo Cloud Builds and local builds
    felgo.setLicenseKey(PRODUCT_LICENSE_KEY);

    // use this during development
    // for PUBLISHING, use the entry point below
    felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));

    // use this instead of the above call to avoid deployment of the qml files and compile them into the binary with qt's resource system qrc
    // this is the preferred deployment option for publishing games to the app stores, because then your qml files and js files are protected
    // to avoid deployment of your qml files and images, also comment the DEPLOYMENTFOLDERS command in the .pro file
    // also see the .pro file for more details
    //felgo.setMainQmlFileName(QStringLiteral("qrc:/qml/Main.qml"));

    engine.load(QUrl(felgo.mainQmlFileName()));

    // to start your project as Live Client, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...",
    // and uncomment the line below
    //FelgoLiveClient client (&engine);

    return app.exec();
}
Jeff B
  • 33
  • 4

1 Answers1

0

I found this link, maybe can help you. QML Application Tutorial, with python https://doc.qt.io/qtforpython/tutorials/qmlapp/qmlapplication.html

I am interested in your solution.

  • Thanks for your help. I have worked through the tutorial you linked to in the past. The challenge isn't with getting qml to work with python, it's just trying to use the additional components and ecosystem the Team at Felgo has created. They enable a significant time savings over straight qml and QtQuick, but have C++ in mind for development and testing (understandably). – Jeff B Dec 06 '20 at 23:30
  • @JeffB Hi,Friend I have met the same problem as you, but I am not good at c++, I just want use felgo framework in pyqt5 style, do you have any solution to solve it, hope you can update this post. – jett chen Aug 21 '21 at 10:02
  • Unfortunately, I wasn't able to find a solution. I had to go a different route and not use Felgo when using PySide2. Since PySide2 (or PySide6) and PyQt5 are are similar frameworks with both being ports to python, the challenges are probably similar in nature. Since I'm in the same boat with limited skills in C++, I wasn't able to figure it out or create a path with it. – Jeff B Aug 21 '21 at 14:41