大廈QML項目關閉此Pyside教程: http://qt-project.org/wiki/PySide_QML_Tutorial_Advanced_1 http://qt-project.org/wiki/PySide_QML_Tutorial_Advanced_2 http://qt-project.org/wiki/PySide_QML_Tutorial_Advanced_3 http://qt-project.org/wiki/PySide_QML_Tutorial_Advanced_4如何動態實例在Pyside
我試圖盡一切Python和沒有任何Java腳本。
我呼籲這是很好的描述爲「動態對象管理」這裏QDeclarativeComponent的的CreateObject()方法時,遇到的唯一困難: http://qt-project.org/doc/qt-4.8/qdeclarativedynamicobjects.html
因此,這裏是一個光禿禿的骨頭的例子,導致錯誤:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import *
class MainWindow(QDeclarativeView):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setWindowTitle("Main Window")
# Renders game screen
self.setSource(QUrl.fromLocalFile('game2.qml'))
# QML resizes to main window
self.setResizeMode(QDeclarativeView.SizeRootObjectToView)
# a qml object I'd like to add dynamically
self.component = QDeclarativeComponent(QDeclarativeEngine(), QUrl.fromLocalFile("Block2.qml"))
# check if were ready to construct the object
if self.component.isReady():
# create the qml object dynamically
dynamicObject = self.component.createObject(self.rootObject())
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the main window
window = MainWindow()
window.show()
# Run the main Qt loop
sys.exit(app.exec_())
隨着主窗口QML文件內容( 「game2.qml」):
import QtQuick 1.0
Rectangle {
id: screen
width: 490; height: 720
SystemPalette { id: activePalette }
}
和QML對象,我想動態構造( 「Block2.qml」):
import QtQuick 1.0
Rectangle {
id: block
}
當我運行這段代碼,它崩潰的:
dynamicObject = self.component.createObject(self.rootObject())
有:
TypeError: Unknown type used to call meta function (that may be a signal): QScriptValue
我知道父母必須是QObject,但除此之外,我不完全確定文檔中應該包含多少內容: http://srinikom.github.io/pyside-docs/PySide/QtDeclarative/QDeclarativeComponent.html
這是不是在C++按照問題: https://qt-project.org/forums/viewthread/7717
它清楚地只是一個問題Pyside目前。
任何想法可能會導致此問題?潛在的錯誤?