近年来,QMl被Qt官方夸得天花乱坠,作为一枚传统的Qter,习惯了用QWidget,毋容置疑的是qml做出来的页面确实炫酷,那么如何在传统的qwidget中嵌入qml呢?倒腾了一上午,终于摸清了他的套路
qt版本:5.12
1.首先创建一个传统的QApplication 应用程序
2.添加新文件选择QMLFILE
3.编写qml
import QtQuick 2.0
Item {
signal signal2Widget
signal signal2qml
Rectangle{
id:root
color:"green"
width: 200
height: 200
Text {
id: mytext
anchors.bottom: parent
text:CppData.getCurrentDateTime()
}
Connections{
target: CppData
onRefshTime:{
mytext.text = CppData.getCurrentDateTime()