qml+python 打包成exe
我写了一个非常简单的程序,使用的qml+python,使用cx_Freeze打包,然而出现了错误。
程序如下:
main.py
import sys
from PyQt5.QtCore import QObject, QUrl, Qt
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtNetwork import *
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
ctx = engine.rootContext()
ctx.setContextProperty("main", engine)
engine.load('main.qml')
win = engine.rootObjects()[0]
win.show()
sys.exit(app.exec_())
main.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
signal tabAdded(variant c)
ColumnLayout{
anchors.fill: parent
TabView{
visible: true
id:tabview
Layout.fillHeight: true
Layout.fillWidth: true
}
Button{
text: "add tab"
onClicked:{
var c = Qt.createComponent("tab.qml");
tabview.addTab("tab", c);
var last = tabview.count-1;
var tab=tabview.getTab(last)
tab.active = true; // Now the content will be loaded
tab.title=tab.item.name
console.log(tabview.getTab(last).item);
}
}
Button{
text: "change tab"
onClicked:{
var tab=tabview.getTab(tabview.currentIndex)
tab.title=tab.item.name
}
}
}
}
setup.py
import sys
import os
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
includefiles =['main.qml','main.py','tab.qml']
packages = ['PyQt5.QtQml','PyQt5.QtNetwork']
options = {
'build_exe': {
'include_files':includefiles,
'packages':packages
}
}
executables = [
Executable('main.py', base=base)
]
setup(name='myapp',
version='0.1',
description='Sample cx_Freeze PyQt5 script',
options=options,
executables=executables
)
错误信息如下:
请问我该怎么做呢
回来家结婚
9 years, 8 months ago