[QML] - Minimized window



  • Hi,
    For learning qml i try to write a simple game on my linux machine, i test it on android and my problem is exatly :

    I have a soundtrack in my game and a timer. When i minimize my window i want to stop the audio track and timer, but i don't find a method for my ApplicationWindow to discover if the window is hidden or not.

    Any help appreciate and sorry for my english ;-)

    Thanks

    Stéphane


  • Moderators

    Hi @csgib
    Have a look at the property 'Qt.application.state' as described here:
    http://doc.qt.io/qt-5/qml-qtqml-qt.html#application-prop



  • Ok but i don't understand where / how place the event capture of application.state ... If i understand it's just a property not a event signal, no ?

    Thanks

    Stéphane


  • Moderators

    @csgib
    read about QML's property bindings.
    This way you can use them like signals.



  • Sorry but i don't understand something, i made this :
    ApplicationWindow {
    Application.state: {
    if (Application.state == Qt.ApplicationHidden)
    {
    console.log("I M MINIMIZED")
    }
    }
    }

    But when i compile i have this error :
    QQmlApplicationEngine failed to load component
    qrc:/main.qml:40 Non-existent attached object

    Line 40 is : Application.state: {

    I'm sorry but i'm very new in c++ / qml dev. Thanks for your help

    Stéphane


  • Moderators

    @csgib
    try this:

    Connections {
        target: Qt.application
        onStateChanged:
            if(Qt.application.state == Qt.ApplicationActive) {
                console.log("ACTIVE")
            }
            else if(Qt.application.state == Qt.ApplicationSuspended) {
                 console.log("ISUSPENDED")
            }
    }
    


  • Ok thanks it works. I understand a better now.

    Thanks

    Stéphane


Log in to reply
 

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