Qt 在线升级功能

   开源QSimpleUpdater是一个Qt在线升级模块 ,但是QSimpleUpdater 由于使用了很久以前的版本,并且近几年没有维护,因此其内部好多Qt的widget文件,这些QWidget与项目的整体风格不符合,说白了就是很丑,现在用QML进行改造,只需要俩个QML文件即可。

一,原型图

二,实际效果

三,关键代码

1,这里用QQuickWidget 通过setSource的方式加载QML文件

2,通过 setProperty 来设置qml中的属性。 通过findChild 并在qml中定义objectName 的方式来获取qml中的控件,比如按钮。

3,主要qml文件

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0

Item {
    id:root
    property int space: 10
    property string tipInformation: "没有可用升级"
    property string verInformation: ""
    property string okBtnText: "继续"
    property string cancleBtnText: "确定"
    property real progressValue: 0
    property bool okBtnEnable : false
    property bool cancleBtnEnable : true

    ProgressBar{
        id:progressBar
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.leftMargin: space
        anchors.rightMargin: space
        height: 30
        from: 0
        to:100
        value: progressValue
        onValueChanged: {
            //console.log("valueChanged:"+progressValue)
            if(value>0&&value<100)
                okBtn.enabled=false
            else
                okBtn.enabled=true
        }
    }

    TextEdit{
        id:textEdit
        anchors.left:parent.left
        anchors.right: parent.right
        anchors.top: progressBar.bottom
        anchors.leftMargin: space
        anchors.rightMargin: space
        readOnly:true
        text: verInformation
    }


    Button{
        id:cancleBtn
        objectName:"quitBtn"
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.bottomMargin:  space
        anchors.rightMargin: space
        text: cancleBtnText
        enabled: cancleBtnEnable
    }

    Button{
        id:okBtn
        objectName:"continueBtn"
        anchors.bottomMargin: space
        anchors.right: cancleBtn.left
        anchors.bottom: parent.bottom
        anchors.rightMargin: space
        text: okBtnText
        enabled: okBtnEnable
    }

    Label{
        id:informationLabel
        anchors.leftMargin: space
        anchors.bottom: cancleBtn.top
        anchors.bottomMargin: space
        anchors.left: parent.left
        text:tipInformation
    }


    Label{
        id:tipLabel
        anchors.leftMargin: space
        anchors.bottom: informationLabel.top
        anchors.bottomMargin: space
        anchors.left: parent.left
        text: qsTr("提示")
    }

}
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0

Item {
    id:root
    property int space: 10
    Label{
        id:tipLabel
        anchors.leftMargin: space
        anchors.left: parent.left
        anchors.top: parent.top
        anchors.topMargin: space*2
        text: qsTr("更新还未完成,确定要退出么?")
    }

    Button{
        id:cancleBtn
        objectName:"quitBtn"
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.bottomMargin:  space
        anchors.rightMargin: space
        text: "取消"
    }

    Button{
        id:okBtn
        objectName:"continueBtn"
        anchors.bottomMargin: space
        anchors.right: cancleBtn.left
        anchors.bottom: parent.bottom
        anchors.rightMargin: space
        text: "确定"
    }
}

 

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

土拨鼠不是老鼠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值