Stopping and Restarting while in the background. (Save my Batt.)



  • Qt 5.1.1 and QtQuick 2.0 on Android. I have a program that shuffles over a list of colors. While running on the device if I put the application into the background by hitting home. The Application keeps running while in the background. I would like to stop this then restart it when the application is no longer in the background. How is this accomplished in Qt?

    @import QtQuick 2.0

    Rectangle {
    width: 1280
    height: 800
    color: colorList[colorNdx]
    property variant colorList: ["red", "orange", "yellow", "green", "blue", "indigo", "violet", "white", "black"]
    property int colorNdx: 0
    property int colorCount: colorList.length

    Rectangle {
        anchors.centerIn: parent
        width: 100
        height: 100
        color: "khaki"
        border.color: "black"
        border.width: 3
        radius: 50
    
        Text {
            anchors.centerIn: parent
            text: qsTr("Quit")
        }
    
        MouseArea {
            anchors.fill: parent
            onPressed: parent.color = "pink"
            onReleased: Qt.quit()
        }
    }
    
    Timer {
         interval: 2000
         running: true
         repeat: true
         onTriggered:{
             colorNdx = colorNdx === (colorCount - 1) ? 0 : (colorNdx + 1)
             console.log("color =>", colorList[colorNdx])
         }
    }
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.