我用pyqt5编写了一个简单的hello world。但是当我启动它时,我得到了一个错误:
QQuickView only supports loading of root objects that derive from QQuickItem.
If your example is using QML 2, (such as qmlscene) and the .qml file you
loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur.
To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the
QDeclarativeView class in the Qt Quick 1 module.
我试图解决它,但我想我不明白是什么快乐。可以有人给我详细解释一下这个错误,我该怎么解决它?在
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.0
ApplicationWindow
{
signal btnPlayClicked()
signal btnStopClicked()
id:app
width:Screen.desktopAvailableWidth
height:Screen.desktopAvailableHeight
color:"black"
ToolBar{
y:app.height-height
height:btnPlay.height
Button
{
id:btnPlay
x:app.width/2-btnPlay.width
text:"Play"
onClicked: parent.parent.btnPlayClicked()
}
Button
{
id:btnStop
x:app.width/2
text:"Stop"
onClicked: parent.parent.btnStopClicked()
}
}
}
错误消息非常清楚:ApplicationWindow不是QQuickItem,因此不能使用QQuickView来加载它。在
原因是ApplicationWindow和QQuickView冲突,因为它们都继承了QQuickWindow。要加载应用程序窗口,您需要使用QQmlApplicationEngine:
相关问题 更多 >
编程相关推荐