我想在编写python应用程序时使用Felgo工具包来扩展Qt的qml类型,但一直遇到问题,而且还没有很好地安装和运行它。我很好奇,在python应用程序中编写qml时,其他人是否能够成功地使用Felgo库。如果是,你是怎么做到的
以下是我迄今为止所做的工作:
下载Felgo并在QtCreator中运行(此处不使用python)
创建了一个venv,pip将Pyside2安装到venv中
创建了一个非常简单的qml文件,该文件使用Felgo组件和python文件来运行它
//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_())
QQmlApplicationEngine failed to load component
file:///C:/Users/jblos/PycharmProjects/Felgo/TestProject/main.qml:3:1: module "Felgo" is not installed
我忘了什么吗
编辑1:
在将构建Felgo的Qt版本(对我来说是5.13.2)与pyside2版本(pip install pyside2==5.13.2)匹配之后,这解决了我所看到的几个问题。我不再看到“Felgo”没有安装。它还解决了存在循环qml依赖性问题的一些问题
现在,该应用程序将在技术上运行和“工作”,但没有主题出现。简单的按钮或导航栏与显示的实时预览完全不同python vs Felgo Live Preview
查看Felgo main.cpp示例应用程序,它们使用的是一个FelgoApplication类,该类可能正在执行一些可能不会发生的设置或初始化
// 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();
}
我找到了这个链接,也许可以帮你。 QML应用程序教程,使用python https://doc.qt.io/qtforpython/tutorials/qmlapp/qmlapplication.html
我对你的解决方案感兴趣
相关问题 更多 >
编程相关推荐