我用Python和QML编写了一些代码。我想将它打包成.exe但我有一些问题。这是我的代码:
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;
tabview.getTab(last).active = true; // Now the content will be loaded
console.log(tabview.getTab(last).item);
}
}
}
}
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_())
setup.py
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'includes': 'atexit'
}
}
executables = [
Executable('main.py', base=base)
]
setup(name='simple_PyQt5',
version='0.1',
description='Sample cx_Freeze PyQt5 script',
options=options,
executables=executables
)
我使用cx_Freeze
打包代码,但是我收到了以下错误:
Traceback (most recent call last):
"File "E"\python34\lib\sit-packages\cx_Freeze\initscripts\Console.py",
line 27,in <module>
exec(code,m.__dict__)
File"main.py",line 15,in <module>
IndexError: list index out of range
我该怎么办?