实现qml+python打包成exe小程序问题,qmlpython,我写了一个非常简单的程序


我写了一个非常简单的程序,使用的qml+python,使用cx_Freeze打包,然而出现了错误。
程序如下:

main.py

import sysfrom PyQt5.QtCore import QObject, QUrl, Qtfrom PyQt5.QtWidgets import QApplicationfrom PyQt5.QtQml import QQmlApplicationEnginefrom 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.2import QtQuick.Controls 1.1import QtQuick.Layouts 1.1ApplicationWindow {    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 sysimport osfrom cx_Freeze import setup, Executablebase = Noneif 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      )

错误信息如下:

请问我该怎么做呢

报错提示给的很清楚了:
File "main.py",line 15,in
win = engine.rootObjects()[0]
IndexError:list index out of range
main.py第15行
索引超出范围,越界了。

编橙之家文章,

评论关闭