在编写python应用程序时,我希望使用Felgo工具包来扩展Qt的qml类型,但是一直遇到问题,而且没有很好的运气将其启动并运行。我很好奇,在python应用程序中编写qml时,其他人是否能够成功地使用Felgo库。如果是的话,你是如何做到的?
以下是我迄今所做的工作:
//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:
在将Qt的版本Felgo与pyside2版本(pip安装pyside2==5.13.2)进行匹配(对我来说是5.13.2)之后,这解决了我所看到的几个问题。我不再看到"Felgo“没有安装。并解决了存在循环qml依赖问题的一些问题。
现在,该应用程序将在技术上运行,并“工作”,但没有任何主题出现。简单的按钮或导航条看起来与实时预览没有任何相似之处。python与Felgo实况预览
查看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();
}发布于 2020-12-06 13:20:13
我找到了这个链接,也许能帮到你。QML应用程序教程,使用python https://doc.qt.io/qtforpython/tutorials/qmlapp/qmlapplication.html
我对你的解决方案感兴趣。
https://stackoverflow.com/questions/65032211
复制相似问题